码迷,mamicode.com
首页 > 数据库 > 详细

SQL 的join 区别

时间:2014-09-02 11:58:24      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   strong   ar   div   sp   on   c   

----------------------INNER JOIN--------------------------- 
1. 三表联合查询
select XX,XX  from a , b , c 
笛卡尔积,等同于cross join
 
2. cross join
--列出两边所有组合,也叫笛卡尔集A.Rows * B.Rows
select *
from Sales S cross join Customers C
 
3. inner join = join
--两边都有的才筛选出来
select *
from Sales S inner join Customers C
on S.Cust_Id = C.Cust_Id
 
----------------------OUTER JOIN--------------------------- 
4. left join = left outer join
--以左边的表为主表,列出主表所有记录,能匹配就匹配,不匹配的用NULL列出
select * from Customers c left join sales s
on c.cust_id = s.cust_id
 
5. right join = right outer join
--以右边的表为主表,列出主表所有记录,能匹配就匹配,不匹配的用NULL列出
select * from Customers c right join sales s
on c.cust_id = s.cust_id
 
6. Full join = full outer join
--两边都列出来,能匹配就匹配,不匹配的用NULL列出
select *
from Sales S full outer join Customers C
on S.Cust_Id = C.Cust_Id
 
示例======================
 
SELECT A.id, rule_id, alarm_name, filter_key, A.subtype, B.name
FROM (
A
LEFT JOIN B ON A.subtype = B.id
)
JOIN C ON C.alarm_type = A.type

SQL 的join 区别

标签:style   color   os   strong   ar   div   sp   on   c   

原文地址:http://www.cnblogs.com/huxiaoyun90/p/3950887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!