2013-05-16

[DB] 圖示表示 SQL 的 JOIN 概念

INNER JOIN
select 
 * 
from 
 Table1 t1
inner join 
 Table2 t2 
on 
 t1.kol1 = t2.kol1

LEFT (OUTER) JOIN
select 
 * 
from 
 Table1 t1
left join 
 Table2 t2 
on 
 t1.kol1 = t2.kol1

RIGHT (OUTER) JOIN
select 
 * 
from 
 Table1 t1
right join 
 Table2 t2 
on 
 t1.kol1 = t2.kol1

FULL (OUTER) JOIN
select 
 * 
from 
 Table1 t1
full join
 Table2 t2 
on 
 t1.kol1 = t2.kol1

LEFT (OUTER) JOIN, WHERE IS NULL
select 
 * 
from 
 Table1 t1
right join 
 Table2 t2 
on 
 t1.kol1 = t2.kol1
where 
 t2.kol1 IS NULL

FULL (OUTER) JOIN, WHERE IS NULL
select 
 * 
from 
 Table1 t1
right join 
 Table2 t2 
on 
 t1.kol1 = t2.kol1
where 
 t1.kol1 is NULL or t2.kol1 IS NULL


參考來源:yazilimmutfagi

沒有留言:

張貼留言