Hi everyone,
struggling with writing a query to retrieve valid records from another query, let say "Query1"
This is what I would like my new Query2 to do:
For records with the same Client_id (that appear 1 or more times), and if their order_date and order_type are the same, give me the records whose client_type is NOT "e.client".
For some reason sometimes the same order enters the table twice, and the e.client one is always invalid. Of course I;d like to keep those records where order_date an order_type are different, because they represent distinct orders, does not matter if it is "e.client" or "client".
I hope it is clear, I am struggling with a number of WHERE and HAVING statements that does not give me the intended result.
Any help will be appreciated! Thanks everyone,
Client_id Client_Name order_date order_type cilent_type Intended result 1 Alpha 18/1/2012 Web client Keep 2 Bravo 19/2/2012 Phone e.client Keep 3 Charlie 25/2/2012 Web client Keep 3 Charlie 15/3/2012 Web e.client Keep 4 Delta 17/4/2012 Web client Keep 4 Delta 17/4/2012 Web e.client Remove 5 Echo 17/4/2012 Web e.client Keep 5 Echo 17/4/2012 Phone e.client Keep 6 Golf 25/7/2012 Web client Keep 6 Golf 25/7/2012 Web e.client Remove 6 Golf 30/7/2012 Web e.client Keep
1 and 2 - keep because they exist once.
3. keep due to different order dates
4. Remove the e.client because order_date and order_type are the same
5. keep due to different order types
6. Remove the e.client entry that has a duplicated order_date and order_time.