Jump Start: Make It Count

In the past several Jump Start columns, I've been looking into different aspects of the SELECT statement. Understanding and mastering the SELECT statement is the most important skill for developing database applications. In this issue, I explain how you can make the SELECT statement count.

The SQL SELECT statement's COUNT function can tell you the number of rows in a table, how many unique values are in a column, and the number of unique values for an expression. In its simplest form, COUNT(*) takes no column parameters and returns the number of rows in a table. For example, the following code returns the total number of rows in the Employees table in the Northwind database:

USE northwindGOSELECT COUNT(*) FROM Employees

You can combine the COUNT function with the DISTINCT argument to return the number of unique values in a particular column. For example, to return the number of unique titles from the Employees table, you can use the query

USE northwindGOSELECT COUNT(DISTINCT Title) FROM Employees

You can use multiple instances of the COUNT function to get the number of unique values in multiple columns. The following example retrieves the number of unique titles and countries:

From the Blogs

The quest for the Golden Record to achieve a single, accurate and complete version of a customer record is worth the pursuit to attain survivorship. Record matching and consolidation are only the beginning. Melissa Data takes a new approach. Learn how to apply intelligent rules based on reference data to make smarter and better decisions for data cleansing....More

On SQL Servers where Availability Groups (or Mirroring) isn’t in play, I typically recommend keeping a combination of on-box backups along with copying said backups off-box as well. Obviously, keeping databases AND backups on the SAME server is the metaphorical equivalent of putting all of your eggs in one basket – and therefore something you should avoid like the plague....More

One of the biggest strengths of AlwaysOn Availability Groups is that they allow DBAs to address both high availability and disaster recovery concerns from a single set of tooling or interfaces. But, this doesn’t mean that you won’t still need backups....More