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: 1208
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Join multiple records using splice DFSORT/ICETOOL 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts DB2 Statistics - Using EXPLAIN and qu... DB2 1
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Join files where value in one is betw... DFSORT/ICETOOL 6
Search our Forums:

Back to Top