From the course: SQL Hands-On Practice: Solve Business Problems
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Solution: Employee-manager data with a self join - SQL Tutorial
From the course: SQL Hands-On Practice: Solve Business Problems
Solution: Employee-manager data with a self join
- [Instructor] Now that you've had a chance to work on this problem, can you see the similarities between this one and the intro problem of this chapter? This problem also requires self joining the employees table to itself. However in this problem, we're pulling different fields and filtering the data set. This means we have to really pay attention to which tables we're pulling the fields from and filtering with. It can get really tricky with self joins because both tables have the same column names, but you can't use them interchangeably because of the relationship you defined in the join. Let's start with joining the employees table to itself just as we did in the intro. We'll let the first table represent employees and the second table represent managers since it's joined on the manager ID of the first table. We're going to start out with select and then we're going to use star as a placeholder, but we're going to…