x

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, 2011 at 09:07 PM in Default

avatar 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, 2011 at 09:15 PM

avatar image

Tim
40.4k 39 83 166

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, 2011 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, 2011 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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x148

asked: Sep 01, 2011 at 09:07 PM

Seen: 2336 times

Last Updated: Sep 01, 2011 at 09:53 PM

Copyright 2016 Redgate Software. Privacy Policy