W3. SQL Joins Flashcards
Q: What is the purpose of the SQL JOIN clause?
A: It combines rows from two or more tables based on a related column between them.
Q: Write a query to perform an INNER JOIN on “Orders” and “Customers” using CustomerID.
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
Q: What does an INNER JOIN return?
A: Records that have matching values in both tables.
Q: What are the four types of SQL joins?
(INNER) JOIN: Returns matching records from both tables.
LEFT (OUTER) JOIN: Returns all records from the left table and matched records from the right.
RIGHT (OUTER) JOIN: Returns all records from the right table and matched records from the left.
FULL (OUTER) JOIN: Returns all records when there is a match in either table.
Q: What does a LEFT JOIN do?
A: Returns all records from the left table and matched records from the right table.
Q: What does a RIGHT JOIN do?
A: Returns all records from the right table and matched records from the left table.
Q: What does a FULL JOIN do?
A: Returns all records when there is a match in either the left or right table.
Q: In which SQL JOIN would you get only records that exist in both tables?
A: INNER JOIN
Q: Describe the relationship between “Orders” and “Customers” in the provided example.
A: The CustomerID column in “Orders” refers to CustomerID in “Customers,” linking records between the two tables.