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

Query regarding DB2 Joins


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

New User


Joined: 03 May 2005
Posts: 4

PostPosted: Mon May 09, 2005 12:33 pm
Reply with quote

if we join two tables, ti and t2
in ti there are 3 columns and in t2 there are 4 colums what is the number of colums in the resultant table
Back to top
View user's profile Send private message
ankyhunk

Moderator


Joined: 05 May 2005
Posts: 98
Location: Navi Mumbai, India

PostPosted: Mon May 09, 2005 12:41 pm
Reply with quote

It depends on the condition & the type of the join.
Back to top
View user's profile Send private message
sangeetha

New User


Joined: 06 May 2005
Posts: 4

PostPosted: Mon May 09, 2005 1:35 pm
Reply with quote

can u explain in more detail abt what the condition & type mean
Back to top
View user's profile Send private message
ankyhunk

Moderator


Joined: 05 May 2005
Posts: 98
Location: Navi Mumbai, India

PostPosted: Mon May 09, 2005 1:43 pm
Reply with quote

The columns specified in the select clause & the values on which the join has to take place. Also there are many types of joins. For details refer to DB2 manuals on this site.
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Mon May 09, 2005 8:59 pm
Reply with quote

Hi Sowmya,

Joins are used to extract data from more than one table. We must use a Join condition while joining two tables. The Join condition depends on your business rules that apply on Tables. I will take a simple situation and explain you in detail.

Consider two tables EMP and DEPT with the following structure
EMP ( EMPNO,ENAME,JOB,SAL,DEPTNO) -- Employee details
DEPT(DEPTNO,DNAME,LOC) -- Department details

I need a query which extracts EMPNO,ENAME,JOB,SAL,DNAME and LOC means complete information of an EMPLOYEE. Some columns are from EMP and some are from DEPT. So we need to Join these 2 tables using a Join Condition. The Condition is DEPTNO of EMP is equal to DEPTNO of DEPT. The complete query is as follows..

SELECT EMPNO,ENAME,JOB,SAL,DNAME,LOC FROM EMP,DEPT where emp.DEPTNO=DEPT.DEPTNO;

while accessing DEPTNO we need to specify fully qualified name(Table.Column). Because it is common in both the tables.

emp.DEPTNO=DEPT.DEPTNO - Join Condition

But Its better to go through a material on Joins for full pledged knowledge.

Thanks,
Reddy.
Back to top
View user's profile Send private message
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Tue May 10, 2005 12:23 pm
Reply with quote

Hi,

what ovreddy explained is inner join which gives only the matching rows from both the tables EMP and DEPT.

there are other joins which returns matching and non-matching rows from both the tables depends on join you select.

those are left outer join, right outer join and full outer join.

Cheers...........

pavankumar
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top