1. Learn
  2. /
  3. Courses
  4. /
  5. Hierarchical and Recursive Queries in SQL Server

Connected

Exercise

A CTE for high-paid IT-positions

In the previous exercise, you created a CTE to find IT positions. Now, you will combine these results with another CTE on the salary table. You will use multiple CTE definitions in a single query. Notice that a comma is used to separate the CTE query definitions. The salary table contains some more information about the ID and salary of employees. Your task is to create a second CTE named ITsalary and JOIN both CTE tables on the employees ID. The JOIN should select only records having matching values in both tables. Finally, the task is to find only employees earning more than 3000.

Instructions

100 XP
  • Define the second CTE, ITsalary, with the fields ID and Salary.
  • Find salaries above 3000.
  • Combine the two CTEs using a JOIN of matching IDs and select the name, salary, and position of the selected employees.