> For the complete documentation index, see [llms.txt](https://gyansetu-sql.gitbook.io/sql-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-sql.gitbook.io/sql-programming/sql-select/sql-joins/sql-self-join.md).

# SQL Self JOIN

### SQL Self JOIN

A self JOIN is a regular join, but the table is joined with itself.

#### Self JOIN Syntax

```sql
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;
```

### Demo Database

In this tutorial we will use the well-known Northwind sample database.

Below is a selection from the "Customers" table:<br>

![](/files/-LSY0N6cnx0JjfnNVpZC)

\
SQL Self JOIN Example

The following SQL statement matches customers that are from the same city:<br>

```sql
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;

```
