Professional Documents
Culture Documents
Inner Join Returns Only Rows That Match in Both The Tables
Inner Join Returns Only Rows That Match in Both The Tables
1. Inner Join:
Inner join returns only rows that match in both the tables.
Example:
Self-Join Syntax
SELECT column_list
FROM table_A A
INNER JOIN table_A B ON A.column_name1 = B.column_name2….
WHERE row conditions
Example:
SQL self-join is very useful when you want to retrieve related data storing in one table such as
organizational structure. In our database sample, we have employees table which stores not only
employee data but also organization structure. The column reportsTo specifies the manager of an
employee and is referenced to employeeId column. To list all information of employees and
managers we can use SQL self-join as follows.
employee manager
-------- -------
Nancy Andrew
Janet Andrew
Margaret Andrew
Steven Andrew
Michael Steven
Robert Steven
Laura Andrew
Anne Steven