SQLite Self Join
Self Join
A self join is a regular join, but the table is joined with itself. You must give the table two different aliases.
This example finds the pairs of customers that are in the same city:
Example
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;
Try it Yourself »