?
Solved

SQL Query Help

Posted on 2011-03-10
2
Medium Priority
?
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

741 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