Solved

SQL Query Help

Posted on 2011-03-10
2
291 Views
Last Modified: 2012-05-11
I have atable with 3 columns EmpID, EmpName and ManagerID. Every Employee has amanager and manager also an employee. If i Give EmpID in query it should return me Epmloyee name and manager name. What will be the query ?
0
Comment
Question by:mohantyd
2 Comments
 
LVL 28

Expert Comment

by:Ryan McCauley
ID: 35106056
You don't specify your table name, so I'll assume is "Employees". I think you're looking for:

SELECT e1.EmpName, e2.EmpName as ManagerName
  FROM Employees e1
  JOIN Employees e2
    ON e1.ManagerID = e2.EmpID
 WHERE e1.EmpID = "Your Employee ID Here"

Open in new window

0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 250 total points
ID: 35106195
this might be helpful:-

SELECT e.Name AS 'Employee Name',  m.Name  AS 'Manager Name'
FROM employees AS e LEFT OUTER JOIN employees AS m
ON e.managerID =m.EmpID where e.EmpID='Your Employee ID '   

Open in new window

0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
disk usage reporting tools 27 49
SQL Select Query help 1 34
SQL Server Express automatically execute SQL or SP 8 28
Delete old Sharepoint backups 2 11
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question