7

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.

1
  • Do you mean NULL values in the column? Commented Oct 11, 2011 at 6:52

5 Answers 5

6

If I understand your question correctly:

SELECT ISNULL(col1) + ISNULL(col2) + ... + ISNULL(col16) AS cnt
FROM yourTable
WHERE trackid=100000
Sign up to request clarification or add additional context in comments.

Comments

5
SELECT count(*) from posttracks WHERE Col1 is NULL

Comments

1

I'm assuming you are trying to find the all rows in which at least one column iS NULL.

Say, you have three columns - col1, col2, col3 in your table - table1. then you can write the query as

SELECT COUNT(*) FROM table1 WHERE col1 IS NULL OR col2 IS NULL OR col3 IS NULL.

If you are more columns, join them using OR

Comments

0

select count(*) from posttrack where trackid is null;

Edit: duplicate of previous answer

Comments

0
SELECT count(*) as amount FROM posttracks WHERE trackid IS NULL GROUP BY trackid;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.