A self join allows you to join a table to itself. It is useful for querying hierarchical data or comparing rows within the same table.

A self join uses the inner join or left join clause. Because the query that uses self join references the same table, the table alias is used to assign different names to the same table within the query.

Note that referencing the same table more than one in a query without using table aliases will result in an error.
The following shows the syntax of joining the table T to itself

Syntax:

SELECT
select_list
FROM
T t1
[INNER | LEFT] JOIN T t2 ON
join_predicate;