MySQL find duplicates in multiple columns -


i have table user ids split 2 columns. (to explain little more, capture ids of participants scanning barcodes. barcode scanner function doesn't work whatever reason, allow manual entry of id, if barcode scanner doesn't work.) results in data following:

+------+-----------+ |  id  | id_manual | +------+-----------+ |    | null      |   | null |         |   | b    | null      |   | b    | null      |   | null | c         |   | c    | null      |   | null | d         |   | null | d         |   +------+-----------+ 

i want find of duplicate ids, taking both columns account. it's easy find duplicates in 1 column ("b" , "d"). how find duplicates "a" , "c"? ideally, query find , return duplicates (a,b,c, , d).

thanks!

an advice: field named id m,ust unique , not null. if have structure, can try this:

select id yourtable t id not null ,     (select count(*)     yourtable t2     t2.id = t.id) +     (select count(*)     yourtable t3     t3.id_manual = t.id) > 1  union  select id_manual yourtable t id_manual not null ,     (select count(*)     yourtable t2     t2.id = t.id_manual) +     (select count(*)     yourtable t3     t3.id_manual = t.id_manual) > 1 

you can go on sql fiddle


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -