从此足球运动员表中,您如何选择球员的姓名和队长的姓名?
PlayerID | PlayerName | TeamCaptainID
=====================================
1 | Jay | 5
2 | John | 3
3 | James | 3
4 | Jack | 5
5 | Jeremy | 5
我追求的结果是:
Player | Captain
================
Jay | Jeremy
John | James
James | James
Jack | Jeremy
Jeremy | Jeremy
最佳答案
在同一张表上应用inner join
似乎已足够:
select t1.PlayerName as Player
, t2.PlayerName as Captain
from tbl t1
join tbl t2 on t1.TeamCaptainID = t2.PlayerID
关于sql - 根据另一列从列中检索值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29903085/