如何查询表并从引用同一表的外键中提取相同的列信息? “SELECT FROM FROM FROM INNER JOIN gift ON to = id WHERE id = 1;”会让我得到第一部分,但我不确定如何获得第二部分
答案 0 :(得分:2)
您可以加入users
表两次:
select
u1.name `from`,
u2.name `to`
from gifts g
join users u1 on g.`to` = u1.id
join users u2 on g.`from` = u2.id
where u1.id = 1;