0

I write a recursive query. Problem: a recursive query that show chain management employees that leads to a particular employee('Maria Cameron' with empid=8).Output should be like this:output

and HR.Employees is here: table

and my query is here:

with Managers as
(

SELECT empid, mgrid, firstname,lastname
FROM HR.Employees as h
where mgrid IS NULL
UNION ALL
SELECT e.empid,e.mgrid,e.firstname,e.lastname
FROM HR.Employees as e INNER JOIN Managers m 
ON (e.mgrid = m.empid)
)
 SELECT *
 FROM Managers
 where firstname='Maria' and lastname='Cameron' and empid=8

but this query don't operate correctly and my output is: enter image description here

2
  • 1
    "but this query can't operate correctly." -- can you elaborate? What is not working correctly? Commented Nov 30, 2015 at 14:04
  • @roryap: I edit my question and put output there Commented Nov 30, 2015 at 18:02

1 Answer 1

1

This line here is not correct:

with Managers as
(

SELECT empid, mgrid, firstname,lastname
FROM HR.Employees as h
where 
*******

Where what?

WHERE h.mgrid IS NULL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.