sql - Find duplicates for several columns exclusive ID-column -
i've found lot of answers on how find duplicates including pk-column or without focus on this:
if have table called t1, , columns c1, c2 , c3 query show duplicate values.
select c1, c2, c3, count(*)as dupcount t1 group c1, c2, c3 having count(*) > 1
but more common requirement id of duplicates have equal c1,c2,c3 values.
so need following doesn't work because id must aggregated:
select id t1 group c1, c2, c3 having count(*) <> 1
(the id of duplicates must different columns must equal)
edit:
thank all. i'm suprised how fast people give excellent answers on stackoverflow!
there lot of versions suggested here think came new one.
select * @t t1 exists (select * @t t2 t1.id <> t2.id , t1.c1 = t2.c1 , t1.c2 = t2.c2 , t1.c3 = t2.c3)
Comments
Post a Comment