Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql - Counting NULL always returns 0?

Tags:

mysql

Im trying to get this result:

NULL    350
google  98
yahoo   5
bing    4

With this query:

SELECT engine, COUNT(engine) AS count
FROM visits
GROUP BY engine
ORDER BY count DESC

But it returns:

google  98
yahoo   5
bing    4
NULL    0

How can i solve this?

like image 934
Sultanen Avatar asked Oct 22 '22 01:10

Sultanen


1 Answers

Use COUNT(1) instead:

SELECT engine, COUNT(1) AS count
FROM visits
GROUP BY engine
ORDER BY count DESC;
  • SQL Fiddle Demo
like image 103
Mahmoud Gamal Avatar answered Oct 23 '22 20:10

Mahmoud Gamal