This is my table structure
groupings
id groupName
1 group1
2 group2
3 group3
4 andSoOn
group_members(correct)
groupingId accountId groupLeader
1 5001 5001
1 5002 5001
2 5001 5001
2 5002 5001
2 5003 5001
3 5001 5001
3 5002 5001
3 5003 5001
3 5004 5001
here’s my problem, every group should be unique, in a way that the members should not be the same in a group…
for example :
group_members(wrong)
groupingId accountId groupLeader
1 5001 5001
1 5002 5001
2 5001 5001
2 5002 5001
2 5003 5001
3 5001 5001
3 5002 5001
3 5003 5001
an insert statement with the groupingId = 3 will fail because 5001,5002,5003 already exists on groupingId = 2
what should be my select statement to check if the members already exists in a group…
btw, im using PHP for this
You need something like this
This will return all groupingIds that have all the relevant accountIds. If it returns nothing you can be sure it is not a duplicate.