Solved

sql query

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now