t-sql exercise - part 3. cte - 3 Using CTEs and Recursive...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
3. Using CTEs and Recursive Queries A Common Table Expression (CTE) is essentially a temporary result set of a query that can be used in a subsequent query to simplify complex query processing. In this exercise you will learn how to create and use queries involving CTEs. Perhaps the most useful application of a CTE is for retrieving hierarchical data. Two common business examples of hierarchically organized data are: (a) the manager-subordinate relationship in an employee hierarchy, and (b) the product-component relationship in a production bill-of-materials. In this exercise you will learn how to use recursive T-SQL CTE queries for this purpose. Before getting started in the readings and code snippets, let’s try to find the starting point of the employee hierarchy. What I want you to do is try to determine who is the boss of all bosses at AdventureWorks. You should be able to find the name of this person using these two tables: A. Write the query to produce the employee ID, employee title (i.e. job position title), and first and last
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern