目的: 兩張表中數據聯系起來查詢符合條件的數據(笛卡爾積)
實現:SQL語句
(1)內連接:join xxx on xxx
1 等值連接 select xxx from table1 (inner:表示內連接,可省略)join table2 on xxx=xxx (鏈接條件) where(數據過濾) xxx=xxx ; 2 非等值鏈接 select xxx from table1 (inner:表示內連接,可省略)join table2 on (鏈接條件)變為:xxx between xxx and xxx where(數據過濾) xxx=xxx ; 3 自鏈接
(2)外連接:
特點:一條一條匹配鏈接時,自動填充null匹配鏈接的表中沒有的數據;與內連接相比查詢記錄條數多;
1 左外鏈接
將join左邊的表中的數據全部找出來
select .. from ... left (outer:可省略) join ... on ... where ...
2 右外鏈接
將join左邊的表中的數據全部找出來
select .. from ... right (outer) join ... on ... where ...