Reputation: 35
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?
Upvotes: 0
Views: 50
Reputation: 861
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.
Upvotes: 1