For pubs
I want to add a stor_name from the stores table into a query but its not working.
The query is:
SELECT
title, COALESCE(SUM(S.qty * T.price), 0) totalsale
FROM
titles T
LEFT JOIN
sales S ON (S.title_id = T.title_id)
GROUP BY
title
ORDER BY
2 DESC
I need to add a stor_name
from the store
table. If I try and add it like this
SELECT
title, COALESCE(SUM(S.qty * T.price), 0) totalsale, stores.stor_name
FROM
titles T
LEFT JOIN
sales S ON (S.title_id = T.title_id)
JOIN
stores ON (S.stor_id = stores.stor_id)
GROUP BY
title
HAVING
stores.stor_name
ORDER BY
2 DESC
The returned result is wrong.