[英]SQL Two foreign keys linked to one primary key of another table to pull field from that table
The question title is probably confusing so I'll try to clear it up.问题标题可能令人困惑,所以我会尝试清除它。
I have two columns in a grid.我在网格中有两列。 State and Locality. State 和位置。 I have two foreign keys in a table.我在一个表中有两个外键。 Notification.fkState and Notification.fkLocality. Notification.fkState 和 Notification.fkLocality。 They are both linked to the primary key of another table.它们都链接到另一个表的主键。 Location.pkLocation I want the ALIASES of State and Locality to equal the Location.Name from the Location Table according to the foreign key value linked the primary key pkLocation. Location.pkLocation 我希望 State 和 Locality 的 ALIASES 根据链接主键 pkLocation 的外键值等于位置表中的 Location.Name。
Is there a statement like有没有类似的声明
SELECT Location.Name(WHERE Notification.fkState=Location.pkLocation) AS State, Location.Name(WHERE Notification.fkLocality=Location.pkLocation) AS Locality FROM Notification INNER JOIN Locality ON Notification.fkState=Location.pkLocation AND Notification.fkLocality=Location.pkLocation
My AND is currently an OR because when it is AND...it displays nothing.我的 AND 目前是 OR,因为当它是 AND 时……它什么也不显示。
Any help?有什么帮助吗?
SELECT S.Name AS Locality, N.Name AS State
From Notification N
Inner Join Location S on N.fkstate=S.pkLocation
Inner Join Location L on N.fkLocality=L.pkLocation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.