반응형
일반적으로는 Inner Join 즉 테이블의 교집합을 Join하지만 join하는 다른 테이블에 데이터가 없더라도 join을 하여 데이터를 얻어 오도록 하는 것이 outer join입니다.
Outer Join에는 다음과 같이 세 가지가 있습니다. LEFT, RIGHT, FULL Outer Join
LEFT OUTER JOIN
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
https://www.w3schools.com/sql/sql_join_left.asp
RIGHT OUTER JOIN
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
https://www.w3schools.com/sql/sql_join_right.asp
FULL OUTER JOIN
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
https://www.w3schools.com/sql/sql_join_full.asp
'서버 개발 > SQL 문법' 카테고리의 다른 글
[MSSQL] 힌트 사용 방법 (0) | 2020.04.22 |
---|