Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us