mysql - SQL Check duplicated values in different fields -


hello have database , table named datalist , has dummy data. here's screenshot of table in phpmyadmin.

enter image description here

what wanted output duplicates in every field. can see there 2 1111 , 2 2222 data, they're both different fields. how can output like:

duplicates: 1111 2222 

i'm sorry question, know checking of duplicate data on same field only. hope can me, thank you!

select   f,   count(*)   overall_occurrences,   count(case when field = 1 f end)   f1_occurrences,   count(case when field = 2 f end)   f2_occurrences,   count(case when field = 3 f end)   f3_occurrences,   count(case when field = 4 f end)   f4_occurrences (      select 1 field, f1 f, datalist.* datalist     union     select 2 field, f2 f, datalist.* datalist     union     select 3 field, f3 f, datalist.* datalist     union     select 4 field, f4 f, datalist.* datalist )    pivotted    somefield = 0 group    f having    count(*) > 1 

edit: updated additionally show duplicates occur.

edit; alternative less repeating of logic...

(possibly not necessary here, example of method can useful in more complex scenarios.)

select   f,   count(*)   overall_occurrences,   count(case when field = 1 f end)   f1_occurrences,   count(case when field = 2 f end)   f2_occurrences,   count(case when field = 3 f end)   f3_occurrences,   count(case when field = 4 f end)   f4_occurrences (      select         pivotter.field,         case pivotter.field             when 1 datalist.f1             when 2 datalist.f2             when 3 datalist.f3             when 4 datalist.f4         end   f,         datalist.*             datalist     cross join     (         select 1 field         union         select 2 field         union         select 3 field         union         select 4 field     )         pivotter )    pivotted    somefield = 0 group    f having    count(*) > 1 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -