课程: Practice It: SQL Joins

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Check it: Self join

Check it: Self join

- Here's a common example of self joins demonstrated within the AdventureWorks database. On the DemEmployee's table, we have the EmployeeKey which is the primary key for the table and of course it is a unique identifier for each employee. Instead of creating a separate table for managers this table includes a ParentEmployeeKey to indicate the employee's direct manager. We can use an inner join from the DemEmployee table to itself, joining the ParentEmployeeKey to EmployeeKey. Let's look at how we would perform this join here. We can write this in the IDE and run the query using the command palette I showed you earlier. In this query, we can use aliases to keep up with the columns for the employee and manager and to find how to join the ParentEmployeeKey and the EmployeeKey. Now, this isn't a super difficult concept but needed to point out that a table can have a relationship with itself and how the inner join comes into play…

内容