Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL count all NULL columns

Tags:

mysql

I need to count and return the number of NULL columns in my MySQL query.

SELECT * from posttracks WHERE trackid=100000;

How would I COUNT all NULL columns?

Edit: to be clear, I don't need the number of rows that have null values, I need the number of columns in the row that have NULL values.

like image 710
user978905 Avatar asked Oct 11 '11 06:10

user978905


2 Answers

If I understand your question correctly:

SELECT ISNULL(col1) + ISNULL(col2) + ... + ISNULL(col16) AS cnt
FROM yourTable
WHERE trackid=100000
like image 67
Mark Byers Avatar answered Sep 24 '22 01:09

Mark Byers


SELECT count(*) from posttracks WHERE Col1 is NULL
like image 35
rahularyansharma Avatar answered Sep 23 '22 01:09

rahularyansharma