A LEFT JOIN should show all rows on the left table however when running the following query, I am only getting place values where there is a count of 1 or more. Please can someone give me some guidance as to where I might be going wrong:
SELECT places.placeId,
placeName,
COUNT(orderId) AS orderCount
FROM places
LEFT JOIN orders
ON places.placeId = orders.placeId
WHERE places.companyId = 1
AND stateId = 1
AND orderstateId = 1
AND orderName NOT LIKE 'Delivery%'
GROUP BY places.placeId,
places.placeName
ORDER BY orderCount DESC,
placeName ASC
Thanks in advance
Your
WHEREcondition converts theOUTER JOINback to anINNER JOIN.The non matched rows will have
NULLfor all theorderscolumns and be eliminated by theWHEREclause. Try this.