SQL Query, get count() to output null instead of 0 I have the following query, which basically counts the how many orders a customer has done:
SELECT name, count(order_id)
FROM customers
LEFT JOIN  orders
ON customers.name == orders.customername
GROUP BY name;

Output is something like this:
-------------
|adam |    2|
|bob  |    0|

Here bob had no entries in the orders table. So I believe the left join creates a table where adam has his order columns filled but bob does not.
But I want 0 to instead be NULL. Like this:
-------------
|adam |    2|
|bob  | NULL|

How can I do this?
Use NULLIF.
SELECT name, NULLIF(count(order_id), 0)
FROM customers
LEFT JOIN  orders
ON customers.name = orders.customername
GROUP BY name;