Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: joining a table to itself


Message #1 by "Arn" <gipanuhot@y...> on Fri, 27 Apr 2001 09:12:55
You can reference the same table thru the aliases:

	select e1.Last_Name_VC,e1.First_Name_VC,e2.Last_Name_VC
+e2.First_Name_VC 'Supervisor'
	from Employee e1 inner join Employee e2 
					on e1.Supervisor_ID = e2.Employee_ID


Eva

-----Original Message-----
From: Arn [mailto:gipanuhot@y...]
Sent: Friday, April 27, 2001 5:13 AM
To: sql language
Subject: [sql_language] joining a table to itself


Suppose I have a table "Employee" with the following columns
       Employee_ID
       Last_Name_VC
       First_Name_VC
       Supervisor_ID
Every employee is assigned a supervisor which also comes from the same 
table. Supervisor_ID contains a reference to the employee table. In other 
words, it's a recursive relationship. 

How should I select all the employees together with their supervisor?
      

  Return to Index