innova
09-10-2007, 01:34 PM
This should be simple, the but the solution is eluding me...
Sample Table/View:
user_id order_id status
1 1 open
1 2 open
1 3 closed
2 4 closed
2 5 closed
I need a query that will get me all the users that have order_IDs that have more than one of the same type of status (WITHOUT specifying what the statuses may be in advance). For example the results I need from this query look like:
order_id
1
2
4
5
Not sure how to do this. Conceptually, its:
select order_id
from table
group by user_id
having count(status)>1
Of course, thats not valid SQL - I'd have to include order_id in the GROUP BY clause, and since order IDs are unique that would give zero results. How do I solve this problem??
Sample Table/View:
user_id order_id status
1 1 open
1 2 open
1 3 closed
2 4 closed
2 5 closed
I need a query that will get me all the users that have order_IDs that have more than one of the same type of status (WITHOUT specifying what the statuses may be in advance). For example the results I need from this query look like:
order_id
1
2
4
5
Not sure how to do this. Conceptually, its:
select order_id
from table
group by user_id
having count(status)>1
Of course, thats not valid SQL - I'd have to include order_id in the GROUP BY clause, and since order IDs are unique that would give zero results. How do I solve this problem??
