[英]sql two columns of one table reference same column in another table
I have these 2 tables 我有这两张桌子
tbl_link
pID | fID_a | fID_b | link_desc
1 | 1 | 2 | aa + bb
tbl_structure
pID | desc
1 | a
2 | b
fID_a and fID_b are foreign keys to pID in tbl_structure fID_a doesn't allow NULL values while fID_b does fID_a和fID_b是tbl_structure中pID的外键fID_a不允许NULL值,而fID_b执行
I am trying to retrieve the desc of structure 2 when querying for structure 1 我在查询结构1时尝试检索结构2的desc
my sql query at the moment looks like this 我的SQL查询此刻看起来像这样
SELECT a.link_desc, tbl_structure.desc FROM tbl_strukture
LEFT JOIN tbl_link as a ON tbl_structure.pID = a.fID_a
LEFT JOIN tbl_link as b ON tbl_structure.pID = b.fID_b
WHERE tbl_structure.pID = 1
but I only get the desc of the structure with pID 1! 但我只得到pID 1结构的desc!
Thanks for your help! 谢谢你的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.