sql表联接

1.join:

表:erp_orders和erp_orders_products

SELECT 
FROM erp_orders_products AS productserp_orders AS orders
WHERE orders.erp_orders_id products.erp_orders_id

2.inner join :

SELECT 
FROM erp_orders_products AS products
INNER JOIN erp_orders AS orders ON orders.erp_orders_id products.erp_orders_id

其实,1,2都是一样的,只不过是表达出来的不一样罢了。

3.LEFT JOIN左连接

LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行

select * from a  life join b on a.id=b.id ;

俗话的理解:b表中有多少条数据,查询出来就有多少条数据,左连接就是按照b中的值,在a表中查询满足条件的值给b。

也可以这样子想,a为满足b的所有的要求。

4.RIGHT JOIN右连接

RIGHT JOIN关键字会右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行。

5.full join 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行.取得并集。

原文地址:https://www.cnblogs.com/kobigood/p/4071530.html