首页 > 代码库 > 【mysql】联合查询
【mysql】联合查询
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 (
JOIN C ON C.alarm_type = A.type
FROM (
A
LEFT JOIN B ON A.subtype = B.id
)LEFT JOIN B ON A.subtype = B.id
JOIN C ON C.alarm_type = A.type
【mysql】联合查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。