标签:
SELECT * FROM Table_A GO SELECT * FROM Table_B GO --内连接 SELECT a.*, b.* FROM Table_A a JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_A a INNER JOIN Table_B b ON a.ID = b.ID GO --内连接等价直接多表from的形式 SELECT a.*, b.* FROM Table_A a INNER JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_A a, Table_B b WHERE a.ID = b.ID --左连接 SELECT a.*, b.* FROM Table_A a LEFT JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_A a LEFT OUTER JOIN Table_B b ON a.ID = b.ID GO --右连接 SELECT a.*, b.* FROM Table_A a RIGHT JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_A a RIGHT OUTER JOIN Table_B b ON a.ID = b.ID --A左连接B 等价于 B右连接A SELECT a.*, b.* FROM Table_A a LEFT JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_B b RIGHT JOIN Table_A a ON a.ID = b.ID --全连接 SELECT a.*, b.* FROM Table_A a FULL JOIN Table_B b ON a.ID = b.ID SELECT a.*, b.* FROM Table_A a FULL OUTER JOIN Table_B b ON a.ID = b.ID --没有 WHERE 子句的交叉联接将产生所涉及的表的笛卡尔积。 SELECT a.*, b.* FROM Table_A a CROSS JOIN Table_B b --如果添加了 WHERE 子句,则交叉联接的行为将与内部联接行为相似 SELECT a.*, b.* FROM Table_A a CROSS JOIN Table_B b WHERE a.ID = b.ID SELECT a.*, b.* FROM Table_A a INNER JOIN Table_B b ON a.ID = b.ID
SQL Server 2008 R2——内连接 左连接 右连接 全连接 交叉连接
标签:
原文地址:http://www.cnblogs.com/zhuyongblogs/p/5176959.html