Brawler
Honorary Master
- Joined
- May 23, 2006
- Messages
- 13,180
- Reaction score
- 4,404
SELECT Customer.name, Customer.surname, Orders.numberOfOrder FROM Customer
JOIN Orders ON
Customer.custID = Orders.custID
WHERE Orders.numberOfOrder <> 1
You shouldn't use the table name "Order". It's a keyword.
Oh yeah, thanks. I should have picked up the order keyword. As I said this is just a silly mock up and the real database in question isn't even looking at customers and orders but the logic is identical.
Regarding the SQL code: That is pretty much identical to what I first did but it doesn't give exactly what I am looking for. That code lists all orders that are not = 1.
Example:
John has orders 1, 2, 3, 4 ,5 etc. That code will select orders 2, 3 , 4, 5 and if I select distinct / group by will just give me his name but it isnt what I'm looking for.
I am looking for code to look through the database for all customers(who have orders) that do not have an numberOfOrder of 1.
So if Peters orders only start from 5 (or any other number greater than 1), he should be included in the report.
Apologies if my original post wasn't clear enough.