Finding duplicates from MySql

Sankar :

lets say I have a validations table like below.

     validation_id    scenario_id
     100              1
     101              1
     102              1
     103              2
     104              2
     100              3
     101              3
     102              3

In the above table if we observe the scenario id's 1 and 3 have the same validation Id's 100, 101 and 102.

In this scenario I can say scenario_id=1 is a duplicate of scenario_id=3.

can I get a MySql query to find such duplicates.

Thanks in advance.

Gordon Linoff :

You can use two levels of aggregation:

select validation_ids, group_concat(scenario_id)
from (select scenario_id,
             group_concat(validation_id order by validation_id) as validation_ids
      from validations v
      group by scenario_id
     ) v
group by validation_ids
having count(*) >= 2;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=25665&siteId=1