SQL Self Join is the kind of join in which a table is joined with itself means we are joining a table with that same table (which is also called Unary relationships), especially when the table has the FOREIGN KEY which references its PRIMARY KEY. If we want to join the table itself means that each row of the table is combined with itself and with every other row of the table.

The self join allows you to join the table to itself. It is useful for querying the hierarchical data or comparing rows within the same table. Till now, we have seen the  Outer Join,  Cross Join,  Left Join,  SQL Joins Overview and  Inner Join in this blog.

#SQL Self JOIN Key Points

  1. The self JOIN occurs when a table takes a ‘selfie.’
  2. The self JOIN is a regular join, but the table is joined with itself.
  3. It can be useful when modeling hierarchies.
  4. They are also useful for comparisons within the table.
  5. You use the self join when the table references data in itself.
  6. One most used example is where you wanted to get a list of employees and their immediate managers.

#sql #sql self join #sql joins overview

SQL Self Join Example | Self Join in SQL Tutorial
1.85 GEEK