![](/img/trans.png)
[英]How to get single row from a query involving two tables. 2 Foreign Keys are repeated in one entry of child table
[英]How use two Foreign Keys inside Single query?
使用location
將sales_person
表連接兩次,以獲取location_to
和location_from
名稱
select t.name,f.name
from location l
join sales_person t on l.location_to = t.id
join sales_person f on l.location_from = f.id
我假設您的sales_person
表中有“ name
列
您也可以對單個查詢使用並集。
select lt.name from location l join sales_person as lt on l.location_to = lt.id
UNION ALL
select lf.name from location l join sales_person as lf on l.location_from = lf.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.