IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Self Join example and please do explain it


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
TS70363

New User


Joined: 07 Apr 2010
Posts: 94
Location: Bangalore, India

PostPosted: Thu Apr 22, 2010 11:17 am
Reply with quote

Hi,,

Can some one provide me with an example of self join and explain it...
I tried so much but could not find some relevant material on it...
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1209
Location: Bangalore,India

PostPosted: Thu Apr 22, 2010 1:31 pm
Reply with quote

Hello There,

Self join is just like any other join except that two instances of the same table will be joined together.

Lets take an example of EMPLOYEE Table which contain rows for each employee in the organisation . Employee can be Manager as well.

Table contain follwoing columns

EMPLOYEE Table
Empid Int
Mgrid Int
Dept Char(25)
Salary Double
Empname Char(35)

So in order to find out the manager of all the Employees u need a self join

Code:
SELECT t1.empname [Employee], t2.empname [Manager]
FROM emp t1, emp t2
WHERE t1.mgrid = t2.empid
 
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts FINDREP before JOIN DFSORT/ICETOOL 3
No new posts DFSORT Join Keys Controlcard DFSORT/ICETOOL 4
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Join multiple records using splice DFSORT/ICETOOL 7
No new posts Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:


Back to Top