Reputation: 2388
What would be better way to implement such view so that the query doesn't take too long.
select * from table
where ID in (
SELECT ID FROM table
GROUP BY ID
HAVING COUNT(ID) > 1
)
Our server will need to run this every 10 mins. I thought of Indexing ID but wasn't sure if that would be the right way to go.
Upvotes: 0
Views: 82
Reputation: 60771
select t.* from table t
join
(
SELECT ID FROM table
GROUP BY ID
HAVING COUNT(ID) > 1
) a
on a.id=t.id
Upvotes: 2