1. 三表联合查询
select XX,XX from a , b , c
笛卡尔积,等同于cross join
4. cross join
--列出两边所有组合,也叫笛卡尔集A.Rows * B.Rows
select *
from Sales S cross join Customers C
5. inner join = join
--两边都有的才筛选出来
select *
from Sales S inner join Customers C
on S.Cust_Id = C.Cust_Id
2. left join = left outer join
--以左边的表为主表,列出主表所有记录,能匹配就匹配,不匹配的用NULL列出
select * from Customers c left join sales s
on c.cust_id = s.cust_id
3. 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