时间:2021-07-01 10:21:17 帮助过:24人阅读
MySQL left join 与 join 有所不同。 MySQL LEFT JOIN 会读取左边数据表的全部数据,即便右边表无对应数据。
MariaDB [test2]> select * from a left join b on a.name=b.name; +------+------+ | name | name | +------+------+ | 3 | 3 | | 4 | 4 | | 1 | NULL | | 2 | NULL | +------+------+ 4 rows in set (0.00 sec)
MySQL RIGHT JOIN 会读取右边数据表的全部数据,即便左边边表无对应数据。
MariaDB [test2]> select * from a right join b on a.name=b.name; +------+------+ | name | name | +------+------+ | 3 | 3 | | 4 | 4 | | NULL | 5 | | NULL | 6 | +------+------+ 4 rows in set (0.00 sec)
两个表的并集
MariaDB [test2]> select * from a left join b on a.name =b.name union select * from a right join b on a.name =b.name; +------+------+ | name | name | +------+------+ | 3 | 3 | | 4 | 4 | | 1 | NULL | | 2 | NULL | | NULL | 5 | | NULL | 6 | +------+------+ 6 rows in set (0.00 sec)
数据库-mysql数据连接
标签:.com alt 没有 多表查询 个数 images icon src adb