x
login about faq Site discussion (meta-askssc)

retrieving manager name from table containing eid, ename and mgrid

Hi ,

I have a table like emp(empid,managerid,empname).i want to retrieve the employee details with their manager name.please help me writing the query .

thanks jaggs

more ▼

asked Sep 01 '11 at 09:07 PM in Default

happy gravatar image

happy
21 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I assume you also have a managers table that would contain something like (managerid, mangername) If so you can join your emp table to the manager table on managerid. Your query would resemble something like

 SELECT E.empid, E.empname, M.managername  
 FROM emp E  
      JOIN manager M on E.managerid = M.managerid  
more ▼

answered Sep 01 '11 at 09:15 PM

Tim gravatar image

Tim
31.5k 20 30 116

there is no manager table ,managerid is the column which is nothing but the empid of the respective manager.so here I think I need to do self join but how i dont know.please help me

Sep 01 '11 at 09:49 PM happy

This should do it.

 SELECT A.EMPID, A.EMPNAME, B.EMPNAME AS MANAGER  
 FROM EMP A  
 JOIN EMP B ON A.MANGERID = B.EMPID
Sep 01 '11 at 09:58 PM Tim
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x100

asked: Sep 01 '11 at 09:07 PM

Seen: 590 times

Last Updated: Sep 01 '11 at 09:53 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.