天天看點

sql 子查詢表級聯查詢

在處理少量資料是使用

示例

select * from A where aid in(select aid from b)

查找a表資料條件aid屬于b表中的aid

select * from A where aid not in(select aid from b)

查找a表資料條件aid不屬于b表中的aid

級聯查詢處理大量資料時使用

執行個體

select a.*,b.* from A a inner join B b on a.aid=b.aid where ......

inner join 如果表中有至少一個比對,則傳回行

select a.*,b.* from A a left join B b on a.aid=b.aid where ......

left join即使右表中沒有比對,也從左表傳回所有的行

select a.*,b.* from A a right join B b on a.aid=b.aid where ......

right join即使左表中沒有比對,也從右表傳回所有的行

select a.*,b.* from A a full join B b on a.aid=b.aid where ......

full join 隻要其中一個表中存在比對,就傳回行

總結:在處理少量資料是可以使用子查詢在出來大量資料使用級聯可提供執行效率