W3. SQL Right Join Flashcards
Q: What does the SQL RIGHT JOIN keyword do?
A: It returns all records from the right table and the matching records from the left table. If there’s no match, it returns 0 records from the left side.
Q: Write the syntax for a RIGHT JOIN.
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
Q: What is another name for RIGHT JOIN in some databases?
A: RIGHT OUTER JOIN
Q: Write a query to return all employees and any orders they may have placed, ordered by OrderID.
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
Q: What happens in a RIGHT JOIN if there is no matching record in the left table?
A: The result will include all records from the right table, and 0 (NULL) for columns from the left table with no match.