![]() The self join is commonly used in processing a hierarchy. Scenario 1: Processing a Hierarchy in SQL Let’s go through some common scenarios that use the self join. Here, we see that the two references to the Employees table are linked by conditioning on the employee’s ManagerId to match the employee ID of the manager. The JOIN keyword connects two tables and is usually followed by an ON or USING clause that specifies the common columns used for linking the two tables. You can see their declaration in the FROM and JOIN clauses. The aliases are in red in the following query. As a good practice, the aliases should indicate the role of the table for each specific reference in a query. For this reason, it is important to use aliases to uniquely identify each reference of the same table in an SQL query. When referring to the same table more than once in an SQL query, we need a way to distinguish each reference from the others. You can find more about the concept of the self join in our article An Illustrated Guide to the SQL Self Join.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |