sql - Select all fields with duplicate entries in a column based on each similar value in another column in MySQL -


sample table

table1  column a, column b, column c blah, 3, blue foo, 3, blue bar, 2, blue joy, 1, red to, 2, red world, 2, red 

i want find values column b same each column c same. end goal create trigger keeps track of these entries , notify users conflict requires attention.

so results should like

blah,3,blue foo,3,blue to,2,red world,2,red 

as in within blues 3 duplicated, in reds 2 duplicated.... on.

if interpreting question properly, use group statement such as

select    count(*) , b , c table1 group b, c 

which give count of rows, , if there duplicate, count greater 1. can filter down return rows have more 1 count, final query might (with @ypercube) :

select    count(*) totalcount , b , c table1 group b, c having count(*) > 1 

Comments