2014.02.13 14:56

SELECT *

FROM Orders order by CustomerID


OrderIDCustomerIDEmployeeIDOrderDateShipperID
10308271996-09-183
10365331996-11-272
10355461996-11-151
10383481996-12-163
10278581996-08-122


SELECT *

FROM Customers


CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constituci� 2222M�ico D.F.05021Mexico
3Antonio Moreno Taquer�Antonio MorenoMataderos 2312M�ico D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK



두개를 LEFT OUTER JOIN 하게 되면


SELECT *

FROM Customers a

LEFT JOIN Orders b

ON a.CustomerID=b.CustomerID

ORDER BY Customers.CustomerName;


CustomerIDCustomerNameContactNameAddressCityPostalCodeCountryOrderIDEmployeeIDOrderDateShipperID
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germanynullnullnullnull
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constituci� 2222M�ico D.F.05021Mexico1030871996-09-183
3Antonio Moreno Taquer�Antonio MorenoMataderos 2312M�ico D.F.05023Mexico1036531996-11-272


결과에서 보면  LEFT OUTER JOIN 은 


ON CustomerID 를 기준으로 Orders 테이블과 일치하는 레코드가 없으면, Orders 테이블의 모든 컬럼이 담긴 row에 NULL을 넣는다


'프로그래밍 > DB_MSSQL' 카테고리의 다른 글

[MS-SQL] 실행계획 Nested Join Merge Join 문제해결  (0) 2015.02.25
[MSSQL] LEFT OUTER JOIN 예제  (0) 2014.02.13
[SQL] dateadd 문법  (0) 2014.02.10
Posted by hoonihoon85 hoonihoon