I am designing a MYSQL database for online tutoring website
Let's say, I have:
- faculty table with (faculty_id, faculty name)
- subject table with (subject_id, subject name)
- student table with (student_id, student name)
- class table with (class_id, faculty_id, student_id, subject_id)
Now I would like to run SQL queries on the class
table to find out all students enrolled with a particular faculty & under a particular subject for which I have:
$sql=("SELECT *
FROM class
WHERE (faculty_id = '" . mysql_real_escape_string($_POST['faculty_id']) . "')
and (subject_id = '" . mysql_real_escape_string($_POST['subject_id']) . "')");
However, I can't seem to figure out how to retrieve student name, faculty name, and subject name instead of just the faculty_id, student_id & subject_id stored in the class
table.
Is there some type of SCHEMA and foreign key relations I need to create which automatically link the ID numbers to their respective rows in the respective tables so i can run UPDATE, DELETE, and INSERT queries based on these ID numbers?
Am I missing something important here? I'm not an expert in DB design. Please help.
INNER JOIN
clause to your query against the other tables you want to bring data in from? - cdhowie