Brawler
Honorary Master
- Joined
- May 23, 2006
- Messages
- 13,180
- Reaction score
- 4,404
Hi. I haven't done SQL in a damn long time. I'd appreciate some help with this rather weird query that I need to run. I've made this one up but the logic is the same.
Bear with me:
2x tables:
Customer(custId, name, surname, etc)
Order(orderId, custId, numberOfOrder)
Clarity on orderId and numberOfOrder: OrderID is just a unique number for each row (PK) and numberOfOrder is the number of the order per customer, i.e. the first order will be 1, the second 2 and so forth.
Obviously each customer can have many orders.
What I want the query to do:
I want to select all of the customers names and surnames who do not have a NumberOfOrder of 1.
I have joined the tables and all and I can easily search for those that have an order number of 1 and then filter them out from the original dataset to get the values I am looking for but I am hoping there is an easier way to do this in SQL?
Bear with me:
2x tables:
Customer(custId, name, surname, etc)
Order(orderId, custId, numberOfOrder)
Clarity on orderId and numberOfOrder: OrderID is just a unique number for each row (PK) and numberOfOrder is the number of the order per customer, i.e. the first order will be 1, the second 2 and so forth.
Obviously each customer can have many orders.
What I want the query to do:
I want to select all of the customers names and surnames who do not have a NumberOfOrder of 1.
I have joined the tables and all and I can easily search for those that have an order number of 1 and then filter them out from the original dataset to get the values I am looking for but I am hoping there is an easier way to do this in SQL?