mysql多表查询sql语句_mysql多表联查 sql语句的的疑惑

关于join, cross join, inner join官方相关描述:

In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.

大意:join, cross join, inner join句法是等价的,但仅仅是当inner join没有使用on的时候,否则就是cross join(交叉连接)

再说,(逗号)操作符,它在语义上也等价于inner join,回到你的问题,select多个表(也就是逗号分割表名)是等同于join的,例如以下是等价的:

select * from t1,t2

等价

select * from t1 join t2

再一个例子:

select * from t1,t2 where t1.id=t2.id

等价

select * from t1 inner join t2 on t1.id=t2.id

但是,真要说区别,就是,(逗号)比其它任何一个join的优先级都要低,尤其在混合,和join的sql语句中。例如:

select * from t1, t2 JOIN t3

等价于

select * from t1,(t2 join t3)

而不是

select * from (t1, t2) join t3

所以如果不注意这个差异,容易踩坑,以上内容大致都来源于mysql手册的join章节,建议楼主至少看三遍以上,链接:https://dev.mysql.com/doc/ref...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值