Hello folks,
I'm having a bit of a nightmare getting a particular query to work the way I want it to.
I have two tables;
One for a catalogue, another for customer orders (which will always be items from the catalogue)
What i'm trying to achieve;
A query that will show order totals for a certain customer account number and catalogue selection (by release date) including zeros (or null values).
The query so far:
SELECT c.cat_number, c.artist, c.title, c.release_date,s.cat_no, s.account_no, SUM(s.ship_qty) AS ordered
FROM catalogue c
LEFT JOIN sales_data s ON c.cat_number = s.cat_no
WHERE c.release_date >= "2011-01-01"
AND s.account_no = "7042"
GROUP BY c.cat_number
This half works....it shows me what the customer has ordered. It doesn't however show me what they haven't ordered. From this catalogue selection there should be 478 results, but this returns 120.....only those ordered by account_no 7042. I want to see the 478 catalogue lines even if not ordered.
Thanks in advance!