- Jul 17, 2001
- 2,344
- 8
- 81
http://sqlfiddle.com/#!2/17bd34/158
So i need to select Bob and Jan with class 1 and 2 respectively.
But class1 demands courses 3 and 4 and course 4 has prerequisites class 1 and 3 so i need to select only course 3 which has one prerequisite which is class 1.
Same for Jan:class 2 demands courses 5 and 8 but 8 also demands class 6 so only class 5 should be selected.
So these are expected results:
Bob | Class 3
Jan | Class 5
I only managed to somehow isolate the problem now I dont know how to continue so that the query will work for people with multiple requirements also,because I could do a GROUP BY HAVING COUNT(*)=1 and this will get my results but this is an accident.Thanks.
So i need to select Bob and Jan with class 1 and 2 respectively.
But class1 demands courses 3 and 4 and course 4 has prerequisites class 1 and 3 so i need to select only course 3 which has one prerequisite which is class 1.
Same for Jan:class 2 demands courses 5 and 8 but 8 also demands class 6 so only class 5 should be selected.
So these are expected results:
Bob | Class 3
Jan | Class 5
I only managed to somehow isolate the problem now I dont know how to continue so that the query will work for people with multiple requirements also,because I could do a GROUP BY HAVING COUNT(*)=1 and this will get my results but this is an accident.Thanks.