扫码关注官方订阅号
一个礼物表: from(赠送者) to(收到者) 一个用户表:id nickname
from和to都关联用户表的id,怎么查询出结果:
赠送者昵称 收到者昵称
认证0级讲师
select * from 礼物 left join 用户 as 发送方 on 礼物.from =发送方.id left join 用户 as 接受方 on 礼物.to = 接收方.id
其中的中文换成对应英文。。。字段自己处理一下
多对多的表连接查询
select usertable1.nickname, usertable2.nickname from gifttable left join usertable as usertable1 on usertable1.id = gifttable.from left join usertable as usertable2 on usertable2.id = gifttable.to
SQL LEFT JOIN 关键字
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
其中的中文换成对应英文。。。字段自己处理一下
多对多的表连接查询
select usertable1.nickname, usertable2.nickname from gifttable left join usertable as usertable1 on usertable1.id = gifttable.from left join usertable as usertable2 on usertable2.id = gifttable.to
SQL LEFT JOIN 关键字