Home >Backend Development >PHP Tutorial >How to write such a sql statement

How to write such a sql statement

WBOY
WBOYOriginal
2016-07-06 13:53:44945browse

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

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn