Solved

sql query

Posted on 2007-11-15
1
181 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to "ASSIGN" a RecordID based on 1st character of a Field? 8 35
Getting the 3 middle digits 4 36
SQL Server Degrading on Write 13 64
Error when saving to sql table a '/' 5 27
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

16 Experts available now in Live!

Get 1:1 Help Now