[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Query Help

Posted on 2011-03-10
2
Medium Priority
?
308 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

656 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