名詞:
內連線:自然連線,只有兩個相匹配的行才能在結果集中顯示
外連線:左外連線、右連線、全外連線
內連線,只顯示滿足where後條件的列 select a.*,b.* from a inner join b on a.id=b.parent_id
左外連線,select a.*,b.* from a left join b on a.id=b.parent_id 左列為主,右表為副表。
右外連線, select a.*,b.* from a right join b on a.id=b.parent_id 左列為副表,右表為主表
全外連線,select a.*,b.* from a full join b on a.id=b.parent_id 返回左表和右表的全部值 ,當某錶在一另外一表無匹配值 ,則為空
注意:mysql不支援full join,
實踐操作:1、內連線 select student.name,teacher.high from student inner join teacher on student.id=teacher.id;
2、左外連線 select student.name,teacher.high from student left join teacher on student.id=teacher.id;
3、右外連線 select student.name,teacher.high from student right join teacher on student.id=teacher.id;
操作過程中碰到的問題:出現1066號錯誤 ,剛開始為是不能顯示相同的列,實際是語句中缺少 on
Mysql內外連線
1.自然連線 natural join 自然連線將表中具有相同名稱的列自動進行匹配,自然連線不必指定任何同等連線條件也不能認為指定哪些列需要被匹配,自然連線得到的結果表中,兩表中名稱相同的列只出現一次。select from employee natural join department 2.內連...
MySQL中連線查詢之內連線
內連線方式通常包括等值連線,非等值連線,自連線。內連線的特點是連線之後的兩個表等級相同,沒有主副之分,匹配得到就輸出,匹配不到就跳過。先來看三張表 員工表 部門表 薪資等級表 1 等值連線 在連線條件中使用等於號 運算子比較被連線列的列值,其查詢結果中列出被連線表中的所有列,包括其中的重複屬性。問題...
Mysql 內外連線,事物,索引
表的連線分為內連和外連 內連線 內連線實際上就是利用where語句對倆個表形成的笛卡兒積進行篩選,我們前面學的所有連線都是內鏈結 語法 select 欄位名 from 表1 inner join 表2 on 連線條件 and 其他條件 例 顯示smith的名字和部門名稱 外連線 外連線分為左外連線和...