幾個資料庫概念的區別

來源:互聯網
上載者:User

1.where和having

WHERE 子句搜尋條件在進行分組操作之前應用;而 HAVING 搜尋條件在進行分組操作之後應用。所以where後面是不可跟聚會函數( 一種函數,它對一組行中的某個列執行計算,並返回單個值如count()  sum())。

2.exist和in

in 是一個集合運算子,前邊要有一個列名。

exists是一個存在判斷,如果後面的查詢中有結果,則exists為真,否則為假,前邊不能有任何列名。


3.內串連和外串連

內串連:把兩個表中資料對應的資料查出來
外串連:以某個表為基礎把對應資料查出來(全串連是以多個表為基礎)

student表
no name 
1   a   
2   b
3   c
4   d 

grade表
no grade
1    90
2    98
3    95

內串連 inner join(尋找條件中對應的資料,no4沒有資料不列出來)
文法:select * from student inner join grade on student.no = grade.no
結果
student.no name grade.no grade
1  a 1  90
2  b 2  98
3  c 3  95

左串連(左表中所有資料,右表中對應資料)
文法:select * from student left join grade on student.no = grade.no
結果:
student.no name grade.no grade
1                  a         1                90
2                  b         2                98
3                  c         3                95
4                  d

右串連(右表中所有資料,左表中對應資料)
文法:select * from student right join grade on student.no = grade.no 
結果:
student.no name grade.no grade
1                  a          1               90
2                  b          2               98
3                  c          3                95

全串連
文法:select * from student full join grade on student.no = grade.no
結果:
no name grade
1   a          90
2   b         98
3   c         95
4   d 
1   a         90
2   b         98
3   c         95

註:access 中不能直接使用full join ,需要使用union all 將左串連和右串連合并後才可以。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.