Databases Reference
In-Depth Information
Select count(*) as "Total Records" from Person.Contact
Select count(Title)as "Not Null Titles" from Person.Contact
Figure 4-13. Using the COUNT aggregate function
How It Works
The COUNT function has different behaviors depending upon the parameter passed to the
function. If you try COUNT(*) ,the query will return you the number of total records avail-
able in the table as shown in the topmost results: table Person.Contact contains a total
of 19972 records
If you pass a column name to the COUNT function, it will return the total number of
records again, but it will ignore all those rows that contain null values for that column. In
the second query, you are querying the same table, which has listed 19972 records, but as
your second query applies to the Title column, it returns only 1009 records, because this
time it has ignored all null values.
Search WWH ::




Custom Search