mysql左连接语句如何写

WBOY
Release: 2016-06-13 12:42:49
Original
1863 people have browsed it

mysql左连接语句怎么写?

本帖最后由 u010572351 于 2013-06-30 12:01:20 编辑 情况是这样的,三张表的左连接,用户表,商品表,用户购买商品记录表.其中商品记录表记录了用户的id,商品的id,关联了用户表和商品表,要求三张表左连接,查询出包含用户名字,商品名字的商品记录。

users 表:uid ,uname
goods表:gid,gname
shop 表:id,uid,gid

大家看看怎么写啊?

我是这样写的:先连接记录表和用户表,形成一个临时表,再用临时表和商品表左连接,结果是错的,why???
select * from<br />
(shop left join users on shop.uid=users.uid)<br />
as tmp<br />
left join goods on tmp.gid=goods.gid;(提示错误)
Copy after login


这样写是正确的,但是不理解:(没有临时表的概念)
select * from<br />
(shop left join users on shop.uid=users.uid)<br />
left join goods on shop.gid=goods.gid;(貌似正常)
Copy after login


1.我的理解是A左连接B表,会出现一个新的表,新的表再左连接C表,不知道有没有错/
2.我总感觉A左连接B再连接C和A左连接C再连接B不一样。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!