Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have these two tables.

Student Preferences Tables

Student Name------Preference 1------Preference 2------Preference 3-------Group ID
Student A------------Student G-----------Student F------Student G
Student B------------Student H-----------Student K------Student L
Student C------------Student I---------- Student A
Student D------------Student H-----------Student K
Student E
Student F
Student G
Student H
Student I
Student J
Student K
Student L

Groups Table
Group ID
1
2
3

I am creating groups of students, where Preferences = "Preferred Partner/Team Mate". Group Table, Group ID = Group Number (Each group can have min 3 max 4 students ) The way i am trying to implement this is, check for students who have entered 2 or more preferences and make them group. Remaining students with 1, 2 or no preferences can be added together to form groups of 4. Some students may be left out without a group. Any suggestions on implementing this in some other way. It is not necessary that all students have their preferred partner.
Posted
Comments
RedDk 29-Sep-13 15:34pm    
Repost

http://www.codeproject.com/Questions/660322/Divide-students-in-groups-based-on-preferences

1 solution

Personally I would change the structure of the tables before proceeding further.

Instead of storing the preferences in separate columns, normalize the data and use another table. In this case it would mean that you would have tables like:

Student
-------
- studentid
- name
- ...

StudentPreference
-----------------
- studentid
- preferencestudentid

This would make it easier to later find preferences, handle the changes in preferences and so on.
 
Share this answer
 
Comments
Mubshir 29-Sep-13 7:37am    
I have made changes to my database as you advised. Do you have any suggestions on how can i implement this?
Wendelius 29-Sep-13 7:55am    
What are you stuck in?
Mubshir 29-Sep-13 8:35am    
I have to approaches in my mind.
First i can check for all students who have entered at least 2 preferences and create a group of them. Than check for students who have 1 preference and create a group and add 1 student who don't have any preference. But i can't figure out how i will be able to avoid situations Like, For example, Student A has added all preferences which include Student B . Student B has also entered 3 preferences which include Student A + 2 different students from Student A's preferences. It is very unlikely that it will happen though.
Second way is like this.
Student A has entered student B as preference. I will check if Student B also has added student a as preference than i will group them together but i have no idea how to achieve this.
Wendelius 29-Sep-13 9:14am    
So if I understood correctly, you worry about 'duplicate' references when the reference is both ways? For example:
studentid preferencestudentid
1 2
1 3
1 4
2 1
2 3
2 4

Is this something you want to avoid? If so, you could create a trigger on the table to check if such preference already exists but in opposite way. Also a unique constraint would take care that the sae preference cannot be added twice.
Mubshir 29-Sep-13 9:18am    
I get it, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900