mysql - How can I delete rows from a table based on duplicates in once column but differences in another? -


I have some data pollution in the table which is taking me out of a difficult time ... I have decided the reason for pollution Because of this it will not happen again, but I have a bunch of records which I need to remove and it is difficult to figure out how

the nature of the problem is as follows:

I have a table that contains userIds and groupIds. It is not so that I can solve with a unique collaboration.

In my case, assuming that groups 4 and 5 are mutually exclusive can not be both)

I need to run a delete on the user_groups table where I can say ( In English): Delete this line if user id = x and group id = 4 if there is also a line where user id = x and groupID = 5

I do not want to delete all the rows where the group id = 4 applies only to users who have a line that contains groupID = 5.

All the much appreciated help

This will delete all users in group 4 Who have duplicates in Group 5.

 Delete as user_groups G1 WHERE G1.groupID = 4 and G1.userID IN (User_Groups WHERE G2.userID = G1.userID and G2.GroupID = 5 from SELECT G2.userID) < / Code>   

Comments