I have to filter orders which do not have a specific product.
It is simple, but the problem is that every order could have many lines, containing different products.
Here is an example of my data:
ID | Product | Customer | Quantidy | Date
1 | Apple | Alex Sorensen | 3 | 17.4.2009
2 | Orange | Alex Sorensen | 1 | 17.4.2009
3 | Lime | Alex Sorensen | 4 | 17.4.2009
4 | Apple | Fred Jonsson | 1 | 30.5.2010
5 | Lime | Fred Jonsson | 7 | 30.5.2010
ect...
Lines with the same date
and the same customer
are for the same order.
How can I find all the orders which do not have (for example) Orange
in their order?
My own (not working) MySQL-code:
SELECT o.ID, k.Customer, o.Quantidy, p.Product, o.Date
FROM Products p, Orders o, Customers c
WHERE p.ID = o.ID
AND k.Customer = o.Customer
AND p.Product NOT IN ('Orange')
GROUP BY o.Date
ORDER BY o.ID DESC
The problem is, that even though I don't want "Alex Sorensen's" order, because it contains oranges, I get his other lines without the one containing "Orange".
I need an SQL-code to give me "Fred Jonsson"s and the other orders, that don't have oranges in the order.