PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

这样的sql语句怎么写

原创
2016-07-06 13:53:44 732浏览

一个礼物表: from(赠送者) to(收到者)
一个用户表:id nickname

from和to都关联用户表的id,怎么查询出结果:

赠送者昵称 收到者昵称

回复内容:

一个礼物表: from(赠送者) to(收到者)
一个用户表:id nickname

from和to都关联用户表的id,怎么查询出结果:

赠送者昵称 收到者昵称

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 关键字

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。