joins型別名詞

yezhibin發表於2009-11-11
在閱讀英文資料時候,經常會讀到join型別的英文單詞,以下是總結join 型別的含義:

1、cross joins,也叫做cartestian product,意思是將表A的每一行與表B的所有行組和起來,語句如下:
    
       SQL>select  * from tab1, tab2
   或
       SQL>select * from tab1 cross join b

2、Theta Joins : 從cross join的結果集中挑選出符合關聯條件的行,類似如下:

      SQL> select * from tab1, tab2
                  where tab1.col1 between tab2.col1 between tab2.col2
   或
     SQL>select * from tab1, tab2
               where tab1 join tab2 on tab1.col1 between  tab2.col1 between tab2.col2

   或
     SQL>select * from tab1, tab2
               where tab1 inner join tab2
               on tab1.col1 between  tab2.col1 between tab2.col2

3、Equi-Joins:是Theta join的特殊型別,關聯條件是“=”,如:
   
       SQL>select * from tab1, tab2
                  where tab1.col1=tab2.col2
   或
      SQL>select * from tab1, tab2
                where tab1 join tab2 on tab1.col1=tab2.col1

4、self-join: 是Theta關聯的特殊型別,表自己關聯自己

      SQL>select * from tab1, tab1 tab2
               where tab1.col1=tab2.col2
    或
     SQL>select * from tab1, tab1 tab2
                where tab1 join tab1 tab2 on tab1.col1 = tab1.col2

5、outer-joins: 是theta joins結果集的擴充套件,顯示一個表的所有結果集,即使該表關聯條件值與另一個表不匹配。

      SQL>select * from tab1, tab2
                where tab1.col1=tab2.col1(+)

     SQL>select * from tab1, tab2
               where tab1 left join tab2 on tab1.col1=tab2.col1

     SQL>select * from tab1, tab2
               where tab1 left outer join tab2 on tab1.col1=tab2.col1

6、semi-joins: 一張表匹配另一個表的行,通常被寫成IN或EXISTS

       SQL>select * from tab1
                  where tab1.col1 in (select col1 from tab2)
 
       SQL>select * from tab1
                 where exists (select * from tab2 where tab1.col1=tab2.col1)

7、Anti-Joins: 返回一張表不匹配另一張表的行,通常是寫成NOT IN或NOT EXISTS

        SQL>select * from tab1
                  where tab1.col1not in (select col1 from tab2)
 
       SQL>select * from tab1
                 where not exists (select * from tab2 where tab1.col1=tab2.col1)



  

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/354732/viewspace-619381/,如需轉載,請註明出處,否則將追究法律責任。

相關文章