I have two tables in my database
(Prefrences_Table)
--------------------------
|student | Preferences |
--------------------------
Stud A | Stud B
Stud A | Stud C
Stud B | Stud E
Stud B | Stud A
Stud C | Stud F
Stud F | Stud B
--------------------------
(Prefrences_Table)
--------------------------
|student | Group ID/Name |
--------------------------
Stud A |
Stud B |
Stud C |
Stud D |
Stud E |
Stud F |
--------------------------
I am asking each student to give me maximum 7 names, who they want to team up with. then taking this information in account fulfill as many choices as possible and create a team.
These are the rules i have to follow to create teams.
First i will check if "Stud A" has added "Stud B" in his Preferences list, and "stud B" has also added "stud A" in his preference, if both of them have added each other i want to add them in group/team (Do this for all students). Second, Check for one sided preferences, "Stud A" has added "Stud B" in his Preferences but stud B hasn't, and add them in group. Third add all students without preference to random Groups. Each group/team can have 5-8 students.
I can use select t.student, t1.student from Prefrences_Table t inner join Prefrences_Table t1 on t.student = t1.preferences and t.preferences = t1.student and t.student < t1.student to find mutual preferences.
How do i create group numbers and than insert them in student table checking that minimum 5 and maximum 8 students have this id.
Groups are going to be created by clicking a button in the application