我有一张家长device
的桌子,以及division
张桌子.
中间是STAKS和ctrltab表,每个表都具有与device
匹配的属性Device_id,以及连接到pipe_division
表的PIPE_Divition_id.
编辑:应要求,我已在下面添加了示例表
设备表
device_id | name | board_number
--------------------------------
23 Stop1 10
24 Stop2 11
25 Ctrltab1 11
26 Rand_dev 8
停靠台
device_id | label | pipe_division_id | length
23 Stop1: Piano 305 16
24 Stop2: Buffet 306 16
CtrlTab表
device_id | label | pipe_division_id | ctrl_function
25 Ctrltab1 305 open_window
管道分割表
pipe_division_id | label | position
305 Lower Box underneath the stairs
306 Upper Box above the stairs
307 Side Box To the left of the console in the closet
查询的预期结果:
name | board_number | label
Stop1 10 Lower Box
Stop2 11 Upper Box
Ctrltab1 11 Lower Box
本质上,我想 Select device
表中板号大于10的所有器件,这些器件的管道_分区_id是通过连接它们的STOP或ctrltab表找到的.
我试过了
Select name, board_number, pd.label
from device d
JOIN stops s ON s.device_id = d.device_id
JOIN ctrltab ct ON ct.device_id = d.device_id
JOIN pipe_division_id pd ON (s.pipe_division_id = pd.pipe_division_id
OR ct.pipe_division_id = pd.pipe_division_id)
但这并没有带来任何结果,我想这个OR语句是无效的?我宁愿避免使用UNION,因为真正的查询非常长,并且我不想为了在查找PIPE_DIVATION标签方面的微小差异而重复所有文本.