Having Trouble When Selecting Duplicates
Posted: Fri Jun 12, 2009 7:21 am
Imagine having a table of customers
cid | orderid | status (shipped,declined/approved)
1 | 101 | approved
1 | 102 | approved
I want to be able to show only duplicate orders that were approved
In my db table, if I use this query:
I get a bunch of customers who have ordered more than 1 time. Of course, the problem is that they have a whole range of
status updates, from shipped, approved/etc. I only want approved. So I tried this:
It gives me fewer results but there is a flaw. Not all orders for that customer are 'approved'. Some are shipped/pending/etc
I only want records that are multiple orders from the same person while *also* only being 'approved' status. How do I go about
completing the query so only orders that are 'approved' display among the customers that ordered more than 1 product?
Thanks
cid | orderid | status (shipped,declined/approved)
1 | 101 | approved
1 | 102 | approved
I want to be able to show only duplicate orders that were approved
In my db table, if I use this query:
Code: Select all
SELECT * FROM orders GROUP BY (customers_id) HAVING count(customers_id)>1status updates, from shipped, approved/etc. I only want approved. So I tried this:
Code: Select all
SELECT * FROM orders GROUP BY (customers_id) HAVING count(customers_id)>1 AND STATUS='shipped'I only want records that are multiple orders from the same person while *also* only being 'approved' status. How do I go about
completing the query so only orders that are 'approved' display among the customers that ordered more than 1 product?
Thanks