wawaragna
wawaragna

Reputation: 37

Multitable SQL join in MySQL

how can i join multiple tables in one query these are my tables

registration
  registrationid
  regschedid
  studentid

registrationschedule
  regschedid

session
  sessionid
  regschedid
  sessiondate

schedules
  scheduleid
  regschedid
  teacherid

faculty
  teacherid
  fname

I wanted to join them all so that i could get the fname and the session date please help me..

by the way i must specify the registration.studentid so that i could get the actual student

Upvotes: 0

Views: 173

Answers (3)

pcraft
pcraft

Reputation: 156

SELECT * FROM registration 
JOIN registrationschedule ON registration.regschedid=regschedid 
JOIN session ON registration.regschedid=session.regschedid 
JOIN schedules ON regschedid.regschedid=regschedid
JOIN faculty ON schedules.teacherid = faculty.techerid
WHERE student.id = ?

Upvotes: 0

Brandon Frohbieter
Brandon Frohbieter

Reputation: 18139

 SELECT registration.*,registrationschedule.*, session.*,schedules.*,faculty.*
 FROM registration
 LEFT JOIN registrationschedule on registration.regschedid = registrationschedule.regschedid
 LEFT JOIN session on session.regschedid = registrationschedule.regschedid
 LEFT JOIN schedules on schedules.regschedid = session.regschedid
 LEFT JOIN faculty on faculty.teacherid = schedules.teacherid
 WHERE registrationid = 1;

Upvotes: 0

Mark Byers
Mark Byers

Reputation: 838216

To join multiple tables, you use the same technique as to join 2 tables:

SELECT *
FROM registration
JOIN registrationschedule ON registration.regschedid = regschedid
JOIN student ON registration.studentid = student.studentid
--- etc

Upvotes: 3

Related Questions