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