I have a two tables: users and missionInfo. I need to select classes only when all of the users who are in that class completed all missions.
users table:
userID classID
1 1
2 1
3 1
4 2
5 2
missionInfo table:
userID missionID
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
4 1
5 1
5 2
So, I should get back classID 1 because users 1 thru 3 all completed all missions 1 thru 3 and are all part of the same class.
Help?
See it on sqlfiddle.
The
DISTINCTcan be omitted if(userID,missionID)will only appear once in themissionInfotable.The inner query returns
classIDfor every mission that has been completed by all that class’s users; the outer one restricts the results to only those classes who have completed the specified number of missions.