Solved

sql query

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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 …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

17 Experts available now in Live!

Get 1:1 Help Now