Q. What is the SQL query to find the count of records in a table that have a NULL value in a column?


Ans. If you want to find this in any specific column, it’s pretty straightforward…

select count(*) from sometab where somecol IS NULL;

or

select count(somecol) from sometab;

In the latter, each record that has a somecol that is non-NULL will add one to the count, or zero otherwise.

If you want to find a count of records where _any_ column is NULL, unfortunately there aren’t any ways that avoid just listing the columns and OR IS NULL stuff (or something logically similar), ie

  1. select count(*) from sometab where col1 IS NULL or col2 IS NULL or ... or colN IS NULL; 


 

Comments

Popular posts from this blog

SQL Assignment – Module 4

SQL Assignments TABLE

SQL Assignment – Module 1