this is my table test
id identifier
--- ---------
1 zz
1 zzz
3 d
5 w
7 v
8 q
9 cc
9 ccc
here I want to remove the duplicate id's and keep the latest id's. the identifier can have duplicate values it dose not matter but the id's should be unique.
I wrote this query to solve this problem but the problem is that it goes into a infinite loop.
please help me with this as I am not able to see the error. Thanks
delete test
from test
inner join(
select max(id) as lastId, identifier
from test
where id in (
select id
from test
group by id
having count(*) > 1
)
group by id
)dup on dup.id = test.id
where test.id<dup.id