The following query only returns Region Names for regions where there have been orders.
SELECT r.RegionName,
COUNT (DISTINCT o.uid)
FROM Orders AS o
LEFT JOIN Customers AS c ON o.CustomerID = c.uid
LEFT JOIN Regions AS r ON c.Region = r.uid
WHERE (r.RegionName NOT LIKE 'NULL')
AND (r.RegionName <> '')
AND (r.RegionName NOT LIKE 'Region 1')
AND (o.DateOrdered LIKE '7%2011%')
GROUP BY r.RegionName
ORDER BY r.RegionName
How can I modify it so that all region names show up even when the “COUNT” is “0”?
You need to either change your
JOINto Regions to be aRIGHT JOINor make Regions theFROMtable and thenJOINto the other tables from there.I prefer the second method, since it seems more intuitive to me. You care about Regions here and you’re trying to get information about Regions, so that should be in the
FROM(IMO):