MySQl - two counts with different WHERE in one query

Posted by Qiao on Stack Overflow See other posts from Stack Overflow or by Qiao
Published on 2010-04-11T00:23:58Z Indexed on 2010/04/11 0:33 UTC
Read the original article Hit count: 480

Filed under:

table

field1 field2
a       1
b
c       3
e       4
f

I need to count field1 and not empty field2 with on query:

SELECT COUNT(field1) FROM table
+
SELECT COUNT(field2) FROM table WHERE field2 != ''

result should be 5 and 3 in one query.

Is it possible?

© Stack Overflow or respective owner

Related posts about mysql