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 將左串連和右串連合并後才可以。