Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

sql query

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
romeiovasu
Asked:
romeiovasu
1 Solution
 
David ToddSenior DBACommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now