Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get corrupt users with multiple ids values in different column of same table

There are around 5 million users in a table having 4 columns, for each value in userid column there needs to be only one sid value in same table. But there are some corrupt records where some userid having multiple sid. How to retrieve these users using mysql query. Please find below the table structure:

id userid sid

1 12345 a
2 67890 b
3 23456 c
4 45678 d
5 23456 e
6 56789 f
7 78901 g
8 10987 h
9 78901 i
10 45800 j

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here the corrupt records are 23456 and 78901. How to retrieve such user ids in mysql

>Solution :

To find duplicate entries you can use the GROUP BY and HAVING clauses:

SELECT userid
FROM your_table
GROUP BY userid
HAVING COUNT(DISTINCT sid) > 1;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading