Solved

sql query

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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 …

738 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