简体   繁体   English

连接来自更多5个表的多列

[英]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. 我想加盟setid (如外键),它存在于查询中的所有表和还我想加盟lecid其中仅存在lec表和parktable表以及加入weekid在一周parktime表。 I am also trying to join the roomid in rooms table and parktable table. 我也试图加入roomidrooms桌子和parktable表。 All together setid is like a foreign key in all those tables. 全部setid就像所有这些表中的外键一样。 I am looking for a setid which is 48596 . 我正在寻找48596的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. TEMP错误。

Is they a problem with the way I am joining it? 他们加入我的方式有问题吗?

don't use join twice, as you have here: 不要像这里一样使用两次join:

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. 如果速度是您的问题,则可能需要将索引放在要加入的col上以及where子句中:setid,number1等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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