SQL语法中的JOIN类型

这个要弄明白哟。。CROSS JOIN, NATURAL, INNER JOIN ,LEFT OUTER JOIN(LEFT JOIN)

等等。。。。带LEFT,RIGHT的必为OUTER,所以OUTER可省。

INNER的行数只能是小于等于OUTER的行数。

谁在左,则LEFT依谁。返回行业和它一致。

RIGHT亦然。。

SELECT a.account_id, a.cust_id, b.name FROM account a LEFT OUTER JOIN business b ON a.cust_id = b.cust_id;
SELECT a.account_id, a.cust_id, i.fname, i.lname FROM account a LEFT OUTER JOIN individual i ON a.cust_id = i.cust_id;
SELECT a.account_id, a.product_cd, CONCAT(i.fname, ' ', i.lname) person_name, b.name business_name FROM account a LEFT OUTER JOIN individual i ON a.cust_id = i.cust_id LEFT OUTER JOIN business b ON a.cust_id = b.cust_id;
SELECT account_ind.account_id, account_ind.product_cd, account_ind.person_name, b.name business_name FROM (SELECT a.account_id, a.product_cd,a.cust_id, CONCAT(i.fname, ' ', i.lname) person_name FROM account a LEFT OUTER JOIN individual i ON a.cust_id = i.cust_id) account_ind LEFT OUTER JOIN business b ON account_ind.cust_id = b.cust_id;
SELECT pt.name, p.product_cd, p.name FROM product p CROSS JOIN product_type pt;
SELECT a.account_id, a.cust_id, c.cust_type_cd, c.fed_id FROM account a NATURAL JOIN customer c;

SQL语法中的JOIN类型

上一篇:head/tail实现


下一篇:PyCharm配置GitHub