EdomGroup: Inspire, Innovate, Create

Result of COUNT in query of queries

SQL

This is an interesting litle tidbit to keep in mind. What do you get if you count distinct against a table with no records? Here is the example query,

SELECT COUNT(DISTINCT ID) AS UniqueRecords FROM MyTable

If MyTable does not contain any records it will return a result set with a single record with a value 0. Now, what do you get if MyTable is actually a query and you're performing a query of queries? Well, if MyTable is a query with no records then you'll have no records in the result, not a 0 value.

Categories

Monthly Archives

Feeds