Solved

SQL Query Help

Posted on 2011-03-10
2
253 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now