MYSQL Select within same table

前端 未结 2 1343
醉话见心
醉话见心 2021-01-22 04:42

I have a table that I need a MYSQL Select statement so I can find the corrupt data and manually fix it.

Sample table

TABLE_A
id | type | value1 | value2
 1 |          


        
相关标签:
2条回答
  • 2021-01-22 05:40
    SELECT a.id as problem_id
    FROM TABLE_A as a JOIN TABLE_A as b
    ON a.type = b.type
    WHERE a.value1 <> b.value1 OR a.value2 <> b.value2
    GROUP BY problem_id;
    
    0 讨论(0)
  • 2021-01-22 05:40

    Try with:

    SELECT * FROM TABLE_A WHERE type IN (SELECT type FROM TABLE_A GROUP BY `type`, `value1`, `value2` HAVING count(value1) > 1 OR count(value2) > 1)
    
    0 讨论(0)
提交回复
热议问题