I want users to be able to select their majors.
For example, person A could select computer science, mathematics, and history as his majors. Users can select any number of majors.
I have a list of organizations in my database that would only accept students if they are of a particular major. For example, Organization A only accepts computer science and mathematics majors. Organizations can select any number of majors.
I want to match students to the organizations that fit their majors. For example, I want to search the database for organizations that accept one or more of Person’s A majors, which are computer science, mathematics, and history. Organizations that accept all or most of Person’s A majors would be listed first. So if Organization B accepts all three of Person’s A majors but Organization A only accepts two of Person’s A majors, Organization B would be listed first.
How can I store the majors that the organizations accept in the mysql database? How can I store students’ majors to allow for efficient matching between student information and organization information?
I was considering storing all the majors that organizations accept as a serialized values in the database.
So I have 2 tables
Organizations
ID int
name varchar(255)
majors_accepted blob
Students
ID int
name varchar(255)
majors blob
I could store the majors that organizations accept as serialized values in the majors_accepted blob. There could be more than 1 major in that field.
Or I could store the majors that students are considering as serialized values in the majors field in the Students table. There could be more than 1 major in that field. Then I guess I could go over all the rows in the organizations table and compare each majors_accepted field with the students data. But that seems inefficient…
I would do it like this:
It’s not good database design to store more than one value in a field like what you’re trying to do with your blobs, so break it out like this, and you can do all the queries necessary to determine which organizations a student can join by just joining tables.
Let’s say you’re looking for the organizations that one particular student can join (we’ll say studentID for this student is 1):