關於資料庫內連線外連線左連線右連線

2021-08-29 17:33:06 字數 1199 閱讀 9494

資料庫內連線、外連線(左連線、右連線)、全連線

內連線:把兩個表中資料對應的資料查出來

外連線:以某個表為基礎把對應資料查出來

全連線是以多個表為基礎

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 將左連線和右連線合併後才可以 

關於資料庫內連線外連線左連線右連線

資料庫內連線 外連線 左連線 右連線 全連線 內連線 把兩個表中資料對應的資料查出來 外連線 以某個表為基礎把對應資料查出來 全連線是以多個表為基礎 student表 no name 1 a 2 b 3 c 4 d grade表 no grade 1 90 2 98 3 95 內連線 inner j...

資料庫 內連線 左外連線 右外連線 全外連線

內連線中,只有滿足連線條件的元組才能作為結果輸出,即當任乙個表中為null則不會輸出。sql 語句 123 select first.cno,second.cpno from course first,course second where first.cpno second.cno 如果在查詢時需...

資料庫 內連線 左外連線 右外連線 全外連線

內連線中,只有滿足連線條件的元組才能作為結果輸出,即當任乙個表中為null則不會輸出。sql 語句 123 select first.cno,second.cpno from course first,course second where first.cpno second.cno 如果在查詢時需...