Reputation: 1188
receipt_id order_id
1 A
2 B
3 B
4 C
5 C
What is the sql code to show all the records in this table where order_id's count is more than 1?
Upvotes: 0
Views: 311
Reputation: 12774
Try this:
Select * from table where order_id in (select distinct order_id
from table
group by order_id
having count(order_id) > 1)
Upvotes: 1
Reputation: 247690
You just need an aggregate function with a GROUP BY
select order_id
from yourtable
group by order_id
having count(order_id) > 1
Upvotes: 3