且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

2个外键在MySQL中引用相同的主键

更新时间:2023-02-02 23:15:38

您需要使用两个联接来完成此操作.

You need to use two joins to accomplish this.

例如:

select f.friendsID, 
  s1.name as personA_name, 
  s2.name as personB_name
from friends f
  inner join student s1 on s1.sID = f.personA
  inner join student s2 on s2.sID = f.personB