select a.id,score from (select id,age from stu where age < 20) a (過濾左表信息) left join (select id, score from result where score < 60) b (過濾右表信息) on a.id = b.id; 左外連接就是左表過濾的結果必須全部存在。如果存在左表中過濾出來的數據,右表沒有匹配上,這樣的話右表就會出現NULL;
(2)右外連接查詢
select a.id,score from (select id,age from stu where age < 20) a (過濾左表信息) right join (select id, score from result where score < 60) b (過濾右表信息) on a.id = b.id; 左外連接就是左表過濾的結果必須全部存在
我們發現過濾出來的表進行的匹配只有兩條滿足條件(紅色代表條件滿足),但最后的結果卻是:
左表不匹配的數據改為空,右表過濾出來的數據都要存在。
(3)全外連接查詢
結合了左外連接和右外連接,使得左表和右表的數據都存在。
2、內連接查詢
只篩選匹配結果
只匹配我們需要的結果
語句為:
select a.id,score from (select id,age from stu where age < 20) a (過濾左表信息) inner join (select id, score from result where score < 60) b (過濾右表信息) on a.id = b.id; 以上是“mysql數據庫如何實現查詢語句”這篇文章的所有內容,感謝各位的閱讀!