Monday, January 12, 2015

SQL COUNT and Nullable Columns

SQL aggregates ignore NULL values in columns.  I knew that  but here's something I'd never really thought of.  If you run a count against a specific field, say COUNT(MyNullableColumn), it won't count records where the value of MyNullableColumn is NULL.  However, if you use COUNT(*) instead it will count all records.  Makes sense.  Just never really considered it.

No comments:

Post a Comment