/*外连接分为左外连接,右外连接,全连接*/
/*左外连接*/
SELECT *
FROM vendors LEFT OUTER JOIN products
ON vendors.vend_id = products.vend_id;
/*右外连接*/
SELECT *
FROM vendors RIGHT OUTER JOIN products
ON vendors.vend_id = products.vend_id;
/*全连接*/
SELECT *
FROM vendors
LEFT JOIN products
ON vendors.vend_id = products.vend_id
UNION
SELECT *
FROM vendors
RIGHT JOIN products
ON vendors.vend_id = products.vend_id
WHERE vendors.vend_id IS NULL ;
内连接分为相等链接,自然连接,交叉连接
/*相等链接*/
SELECT vend_name,prod_name,prod_price
FROM vendors INNER JOIN products
ON vendors.vend_id = products.vend_id;
/*自然连接*/
SELECT *
FROM vendors NATURAL JOIN products;
/*交叉连接*/
SELECT *
FROM vendors CROSS JOIN products;
/*左外连接*/
SELECT *
FROM vendors LEFT OUTER JOIN products
ON vendors.vend_id = products.vend_id;
/*右外连接*/
SELECT *
FROM vendors RIGHT OUTER JOIN products
ON vendors.vend_id = products.vend_id;
/*全连接*/
SELECT *
FROM vendors
LEFT JOIN products
ON vendors.vend_id = products.vend_id
UNION
SELECT *
FROM vendors
RIGHT JOIN products
ON vendors.vend_id = products.vend_id
WHERE vendors.vend_id IS NULL ;
内连接分为相等链接,自然连接,交叉连接
/*相等链接*/
SELECT vend_name,prod_name,prod_price
FROM vendors INNER JOIN products
ON vendors.vend_id = products.vend_id;
/*自然连接*/
SELECT *
FROM vendors NATURAL JOIN products;
/*交叉连接*/
SELECT *
FROM vendors CROSS JOIN products;