Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Query regarding DB2 Joins

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Query regarding DB2 Joins
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject: Re: Query regarding DB2 Joins
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us