內串連(inner join)。
外串連:
全串連(full join)、左串連(left join)、右串連(right join)。
交叉聯結(cross join)。
外串連與內串連不一樣,外串連返回的查詢結果中不僅包含合格行,還包括左表(左外串連),右表(右外串連)或者兩個串連表(全外串連)中的所有不合格資料行。
1.左串連 (left [outer] join)
左外串連就是將左表的所有資料分別於右表的每條資料進行串連組合,返回的結果除內串連的資料外,還有左表中不合格資料,並在右表的相應列中填上null值。
SQL語句如下:
select * from mt_pb_org o left join mt_pb_orgframe f on o.PB_ORGFRAMEID = f.PB_ORGFRAMEID;
等價語句:
select * from mt_pb_org o,mt_pb_orgframe f where o.pb_orgframeid = f.pb_orgframeid(+);
2.右串連 (right [outer] join)
右外串連就是將右表中的所有資料分別與左表的每條資料進行串連組合,返回的結果除了內串連的資料外,還有右表中不合格資料,並在左表相應的列中填上null值。
SQL語句如下:
select * from mt_pb_org o right join mt_pb_orgframe on o.pb_orgframeid = f.pb_orgframeid;
等價語句:
select * from mt_pb_org o,mt_pb_orgframe f where o.pb_orgframeid(+) = f.pb_orgframeid;
3.全外串連 (full [outer] join)
全外串連就是將左表的所有資料分別與右表的每條資料進行串連組合,返回的結果除了內串連的資料外,還有兩個表中不合格資料,並在左表或者右表的相應列中填上null值。
SQL語句如下:
select * from mt_pb_org o full join mt_pb_orgframe o.pb_orgframeid = f.pb_orgframeid;
4.交叉串連(cross join)
交叉串連不帶WHERE 子句,它返回被串連的兩個表所有資料行的笛卡爾積,返回到結果集合中的資料行數等於第一個表中符合查詢條件的資料行數乘以第二個表中符合查詢條件的資料行數。
SQL語句如下:
select * from mt_pb_org o cross join mt_pb_orgframe f;