The document discusses different types of SQL joins including outer joins and self joins. It provides examples and exercises for left, right, full, and self outer joins. The objective is to dive deeper into the intricacies of SQL joins and understand how to use outer joins to return all rows from one or both tables even when there is no match, as well as self joins to compare rows within the same table.
The document discusses different types of SQL joins including outer joins and self joins. It provides examples and exercises for left, right, full, and self outer joins. The objective is to dive deeper into the intricacies of SQL joins and understand how to use outer joins to return all rows from one or both tables even when there is no match, as well as self joins to compare rows within the same table.
The document discusses different types of SQL joins including outer joins and self joins. It provides examples and exercises for left, right, full, and self outer joins. The objective is to dive deeper into the intricacies of SQL joins and understand how to use outer joins to return all rows from one or both tables even when there is no match, as well as self joins to compare rows within the same table.
The document discusses different types of SQL joins including outer joins and self joins. It provides examples and exercises for left, right, full, and self outer joins. The objective is to dive deeper into the intricacies of SQL joins and understand how to use outer joins to return all rows from one or both tables even when there is no match, as well as self joins to compare rows within the same table.
• Objective: Dive deeper into the intricacies of SQL joins, focusing on outer joins and understanding the concept of self joins. SQL OUTER JOINS • An OUTER JOIN keyword fetches the records when there is a match in one of the tables. Therefore, it returns all the rows when there is a match in one of the tables. EXAMPLE: OUTER JOIN • SELECT Customers.CustomerName, Orders.OrderID • FROM Customers • OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID; SQL LEFT OUTER JOIN • The LEFT OUTER JOIN keyword returns all the rows from the left table, and the matching rows from the right table. EXAMPLE: LEFT OUTER JOIN • SELECT Students.Name, Courses.CourseName • FROM Students • LEFT OUTER JOIN Courses ON Students.CourseID = Courses.ID; EXERCISE: LEFT OUTER JOIN • Retrieve all students and their enrolled courses, including students who haven't enrolled in any course. SQL RIGHT OUTER JOIN • The RIGHT OUTER JOIN keyword returns all the rows from the right table, and the matching rows from the left table. EXAMPLE: RIGHT OUTER JOIN • SELECT Orders.OrderID, Customers.CustomerName • FROM Orders • RIGHT OUTER JOIN Customers ON Orders.CustomerID = Customers.CustomerID; EXERCISE: RIGHT OUTER JOIN • List all products and their orders, including products that haven't been ordered yet. SQL FULL OUTER JOIN • The FULL OUTER JOIN keyword returns all the rows when there is a match in one of the tables. It returns all the rows from both tables. EXAMPLE: FULL OUTER JOIN • SELECT Students.Name, Courses.CourseName • FROM Students • FULL OUTER JOIN Courses ON Students.CourseID = Courses.ID; EXERCISE: FULL OUTER JOIN • Retrieve a list of all students and all courses, including students without courses and courses without students. SQL SELF JOIN • A self join is a join in which a table is joined with itself. It is used to compare rows within the same table. EXAMPLE: SELF JOIN • SELECT A.EmployeeName, B.EmployeeName AS 'ManagerName' • FROM Employees A, Employees B • WHERE A.ManagerID = B.EmployeeID; EXERCISE: SELF JOIN • Given a table 'Employees' with an 'EmployeeID', 'EmployeeName', and 'ManagerID', retrieve a list of employees and their respective managers. MASTERING SQL JOINS • A deep understanding of SQL joins, including outer joins and self joins, is essential for complex data retrieval and analysis scenarios. FEEDBACK AND QUESTIONS • Students are encouraged to provide feedback and ask questions at the end of the lab.