gpt4 book ai didi

mysql - 使用先前查询的结果进行sql查询

转载 作者:行者123 更新时间:2023-11-29 07:04:41 26 4
gpt4 key购买 nike

如何查询表并从引用同一个表的外键中提取相同的列信息? “从用户 INNER JOIN 中选择名称,将礼物发送给 = id,其中 id = 1;”会给我第一部分,但我不确定如何获得第二部分。
enter image description here

最佳答案

您可以加入 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;

关于mysql - 使用先前查询的结果进行sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42178401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com