Forum Moderators: coopster
student, subjects, category, majors, interest
student table has a primary key of student_id and every other table has a foriegn key of student_id ...now on a page i want to display all records from tables having foriegn keys where the student_id is let say 1
plz help me out
1. it should fail because student_id in the WHERE clause is ambiguous.
2. If you make it unambiguous, you'll end up with a Cartesian join. You need
WHERE subjects.student_id='1' AND category.student_id='1' etc.
OR
WHERE subject.student_id = category.student_id AND subject.student_id = majors.student_id ... etc ... AND subject.student_id = '1'
OR
SELECT * FROM subjects
INNER JOIN category ON category.student_id= subjects.student_id
INNER JOIN majors ON majors.student_id= subjects.student_id
etc
WHERE category.student_id = '1'
These are all joins, and if my brain is working this morning (big IF), they should all yield the same result set.