Sultanen
Sultanen

Reputation: 3412

Mysql - Counting NULL always returns 0?

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?

Upvotes: 5

Views: 385

Answers (1)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

Use COUNT(1) instead:

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

Upvotes: 3

Related Questions