Q: What is a SQL self join?
A: A self join is when a table is joined with itself.
Q: Why are table aliases needed in a self join?
A: To differentiate between the two instances of the same table.
Q: What is the syntax for a self join?
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;
Q: Write a query to match customers from the same city using a self join.
SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City
ORDER BY A.City;
Q: What does A.CustomerID <> B.CustomerID ensure in a self join?
A: It ensures that the query does not match a customer with themselves.