MySql查询select from 两个表与left join on的区别
Posted wj沧浪之水
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySql查询select from 两个表与left join on的区别相关的知识,希望对你有一定的参考价值。
直接看sql:
mysql>
select
*
from
a;
+
------+------+
| id | col |
+
------+------+
| 1 | 11 |
| 2 | 12 |
| 3 | 13 |
+
------+------+
3
rows
in
set
(0.00 sec)
mysql>
select
*
from
b;
+
------+------+
| id | col |
+
------+------+
| 2 | 22 |
| 3 | 23 |
| 5 | 25 |
+
------+------+
3
rows
in
set
(0.00 sec)
mysql>
mysql>
select
*
from
a,b
where
a.id=b.id;
+
------+------+------+------+
| id | col | id | col |
+
------+------+------+------+
| 2 | 12 | 2 | 22 |
| 3 | 13 | 3 | 23 |
+
------+------+------+------+
2
rows
in
set
(0.08 sec)
mysql>
select
*
from
a
left
join
b
on
a.id=b.id;
+
------+------+------+------+
| id | col | id | col |
+
------+------+------+------+
| 1 | 11 |
NULL
|
NULL
|
| 2 | 12 | 2 | 22 |
| 3 | 13 | 3 | 23 |
+
------+------+------+------+
3
rows
in
set
(0.00 sec)
mysql>
以上是关于MySql查询select from 两个表与left join on的区别的主要内容,如果未能解决你的问题,请参考以下文章