简体   繁体   中英

Joining multiples columns from more 5 tables

I am trying to join setid (like a foreign key) which exist in all the tables in the query and also I am trying to join lecid which only exist in lec table and in parktable table as well as joining weekid in week and parktime table. I am also trying to join the roomid in rooms table and parktable table. All together setid is like a foreign key in all those tables. I am looking for a setid which is 48596 .

I have tried:

select t.slotid, r.number1, t.weekid, t.duration, p.name as DEPName, 
a.name  FROM parktime t

JOIN rooms k ON t.setid = k.setid

JOIN week r ON t.setid = r.setid

JOIN structure w ON t.setid = w.setid


FULL OUTER JOIN LEC p 
ON
t.LECID = p.LECID

FULL OUTER JOIN week r
ON t.weekid = r.weekid

FULL OUTER JOIN structure w 
ON

r.number1 = w.number1

FULL OUTER JOIN rooms k
on
k.roomid = t.roomid

WHERE t.setid  = '48596'

The problem is that this query takes too long to run and at the end of it, it doesn't come back with the result. TEMP error.

Is they a problem with the way I am joining it?

don't use join twice, as you have here:

FULL OUTER JOIN JOIN rooms k

If speed is your issue, you may want to put indexes on the cols that you are using to join and in the where clause: setid, number1, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM