Home >Backend Development >PHP Tutorial >How to write such a sql statement
A gift table: from (giver) to (receiver)
A user table: id nickname
From and to are both associated with the id of the user table. How to query the results:
Giver’s nickname Receiver’s nickname
A gift table: from (giver) to (receiver)
A user table: id nickname
From and to are both associated with the id of the user table. How to query the results:
Giver’s nickname Receiver’s nickname
<code>select * from 礼物 left join 用户 as 发送方 on 礼物.from =发送方.id left join 用户 as 接受方 on 礼物.to = 接收方.id</code>
Replace the Chinese characters with their corresponding English counterparts. . . Handle the fields yourself
Many-to-many table connection query
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 keyword