Find more than three columns having equal value in mysql

I have multiple columns have equal value. I want to find the row id for which more than three columns have equal value.

@each column is text/blob

The table structure is similar -

id  col1 col2 col3 col4 col5 col6 col7 col8 col9
+4
source share
1 answer

Unpivotdata and check equality. Try this trick.

SELECT DISTINCT id 
FROM   (SELECT id,col1 AS col from Yourtable
        UNION ALL 
        SELECT id,col2  from Yourtable
        UNION ALL 
        SELECT id,col3  from Yourtable
        UNION ALL 
        SELECT id,col4  from Yourtable
        Union ALL
        .......) A 
GROUP  BY id,col 
HAVING Count(1) > 3 
+3
source

Source: https://habr.com/ru/post/1619605/


All Articles