Solved

sql query

Posted on 2007-11-15
1
183 Views
Last Modified: 2010-03-19
i have an sql table with table strucutre

id  autonumber
supervisorid number
firstname text
lastname text

how can i write a query to get a report to who is the supervisor for an employee

like
employeefirst and lastname and supervisor for that employee.

0
Comment
Question by:romeiovasu
1 Comment
 
LVL 35

Accepted Solution

by:
David Todd earned 250 total points
ID: 20292313
Hi,

The answer is to do a self-join

HTH
  David
select
	e.firstName as EmFirst
	, e.lastName as EmLast
	, isnull( s.firstName, '' ) as SupFirst
	, isnull( s.lastName, '' ) as SupLast
from dbo.Employees e
left outer join dbo.Employees s
	on e.SuperviserID = s.ID

Open in new window

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Date from a string 4 71
Incremental load example 2 55
Problem with SqlConnection 4 178
Insert from Stored Procedure where some field/s > 0 7 45
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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