left join on

"Persons" 表:spa

Id_P LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

"Orders" 表:it

Id_O OrderNo Id_P
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 65

 

左鏈接(LEFT JOIN)實例

 

SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
LEFT JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

結果集:table

LastName FirstName OrderNo
Adams John 22456
Adams John 24562
Carter Thomas 77895
Carter Thomas 44678
Bush George  

 

LEFT JOIN 關鍵字會從左表 (Persons) 那裏返回全部的行,即便在右表 (Orders) 中沒有匹配的行。 ast

即保留左邊全部內容,右邊跟隨左邊匹配。class

相關文章
相關標籤/搜索