Tuesday, 28 August 2018
Subscribe to:
Post Comments (Atom)
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
WHERE
condition converts the OUTER JOIN
back to an INNER JOIN
.NULL
for all the orders
columns and be eliminated by the WHERE
clause. Try this.SELECT places.placeId,
placeName,
COUNT(orderId) AS orderCount
FROM places
LEFT JOIN orders
ON places.placeId = orders.placeId
AND orders.stateId = 1
AND orders.orderstateId = 1
AND orders.orderName NOT LIKE 'Delivery%'
WHERE places.companyId = 1
GROUP BY places.placeId,
places.placeName
ORDER BY orderCount DESC,
placeName ASC
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment