TOP

SQL RIGHT JOIN

YouLibreCalc for Excel logo

SQL RIGHT JOIN 설명

RIGHT JOIN 키워드는 오른쪽 테이블(table2)의 모든 레코드와 왼쪽 테이블(table1)의 해당 레코드를 반환합니다.

일치하는 항목이 없으면 결과는 왼쪽부터 0개의 레코드가 됩니다.


RIGHT JOIN 구문

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name
일부 데이터베이스에서는 RIGHT JOIN을 RIGHT OUTER JOIN이라고 합니다.

SQL INNER JOIN

데모 데이터베이스

이 튜토리얼에서는 유명한 예제 데이터베이스 "Northwind"을 사용합니다.

다음은 "Orders"("주문") 테이블의 샘플입니다.

ProductIDOrderIDCustomerIDEmployeeIDOrderDateShipperID
1102489051996-07-043
2102498161996-07-051
3102503441996-07-082
4102518431996-07-081
5102527641996-07-092

그리고 "Employees"("Employees") 테이블에서 선택합니다.

EmployeeIDLastNameFirstNameBirthDatePhotoNotes
1Davolio Nancy 12/8/1968 EmpID1.pic Education includes a BA in psychology from Colorado State University. She also completed (The Art of the Cold Call). Nancy is a member of 'Toastmasters International'.
2Fuller Andrew 2/19/1952 EmpID2.pic Andrew received his BTS commercial and a Ph.D. in international marketing from the University of Dallas. He is fluent in French and Italian and reads German. He joined the company as a sales representative, was promoted to sales manager and was then named vice president of sales. Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.
3Leverling Janet 8/30/1963 EmpID3.pic Janet has a BS degree in chemistry from Boston College). She has also completed a certificate program in food retailing management. Janet was hired as a sales associate and was promoted to sales representative.
4Peacock Margaret 9/19/1958 EmpID4.pic Margaret holds a BA in English literature from Concordia College and an MA from the American Institute of Culinary Arts. She was temporarily assigned to the London office before returning to her permanent post in Seattle.
5Buchanan Steven 3/4/1955 EmpID5.pic Steven Buchanan graduated from St. Andrews University, Scotland, with a BSC degree. Upon joining the company as a sales representative, he spent 6 months in an orientation program at the Seattle office and then returned to his permanent post in London, where he was promoted to sales manager. Mr. Buchanan has completed the courses 'Successful Telemarketing' and 'International Sales Management'. He is fluent in French.

SQL RIGHT JOIN 예

다음 SQL 문은 모든 직원과 직원이 발주한 모든 주문을 반환합니다.

Run SQLSELECT Orders.OrderID, Employees.LastName, Employees.FirstName 
FROM Orders 
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID 
ORDER BY Orders.OrderID
RIGHT JOIN 키워드는 왼쪽 테이블(Orders)에 일치하는 항목이 없더라도 오른쪽 테이블(Employees)의 모든 레코드를 반환합니다.