Home >Database >Mysql Tutorial >About mysql implementation of table join (left, right, inner, full join)

About mysql implementation of table join (left, right, inner, full join)

藏色散人
藏色散人forward
2020-03-20 09:02:012351browse

mysql implements table connection (left, right, inner, full join)

The connection between two tables appears in the query. The following uses examples to explain the differences between various connection queries

Table a, and table b are as shown below

a has abcd in the table

About mysql implementation of table join (left, right, inner, full join)

## b has abcf

in the table About mysql implementation of table join (left, right, inner, full join)

Inner join:

SELECT * from a INNER JOIN b on a.name=b.id;

The result is as shown in the figure, select the equivalent result (abc)

About mysql implementation of table join (left, right, inner, full join)

Left join:

SELECT * from a left JOIN b on a.name=b.id;

The query results are as shown in the figure, select table a as the benchmark. (abcd)

About mysql implementation of table join (left, right, inner, full join)

Right join:

SELECT * from a right JOIN b on a.name=b.id;

The query results are as shown in the figure, select table a as the benchmark. (abcf)

About mysql implementation of table join (left, right, inner, full join)

Full join: mysql does not support full join (full join), you can use left join union right join

(SELECT  * from a left JOIN b on a.name=b.id) UNION   (SELECT  * from a RIGHT JOIN b on a.name=b.id );

The result is that all are displayed , as shown below:

About mysql implementation of table join (left, right, inner, full join)

Recommended mysql video tutorial, address:

https://www.php.cn/course/list/51.html

The above is the detailed content of About mysql implementation of table join (left, right, inner, full join). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete