If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Select statement in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-04, 03:57
IPPOPP IPPOPP is offline
Registered User
 
Join Date: Mar 2004
Posts: 4
Select statement in DB2

I have 2 tables: TAB1 incliudes PRIMARY_PROD_NO and ALT_PROD_NO
TAB2 has PROD_NO (as KEY) and PROD_DESCRIPTION.

How do I code a select statement that will give the result set of:

PRIMARY_PROD_NO, description, ALT_PROD_NO, Description?

Eachh Description relating to each Prod_no.

thank you
IPPOPP
Reply With Quote
  #2 (permalink)  
Old 03-04-04, 04:42
nitingm nitingm is offline
Registered User
 
Join Date: Jul 2003
Location: Austin, TX, USA
Posts: 278
Tables

Hi,

From what I can say it's a simple select, however to put a proper answer we need the tables and if there is a relation.

What I suggest is you use the sql assist function in the command center to help you to the needful.

Please post the above details and we can give you the sql statement.

Regards

Nitin.
__________________
HTH

Nitin

Ask the experienced rather than the learned
Reply With Quote
  #3 (permalink)  
Old 03-04-04, 04:56
Walter Janissen Walter Janissen is offline
Registered User
 
Join Date: Nov 2003
Location: Germany
Posts: 62
Hi

Have you tried:

SELECT PRIMARY_PROD_NO, A.description, ALT_PROD_NO,
B.Description
FROM TAB1
INNER JOIN TAB2 A
ON PRIMARY_PROD_NO = A.PROD_NO
INNER JOIN TAB2 B
ON ALT_PROD_NO = B.PROD_NO
Reply With Quote
  #4 (permalink)  
Old 03-04-04, 21:55
adam_ac adam_ac is offline
Registered User
 
Join Date: Nov 2003
Location: Jakarta, Indonesia
Posts: 32
Another version:

SELECT PRIMARY_PROD_NO, (SELECT DESCRIPTION FROM TAB2 WHERE PROD_NO=PRIMARY_PROD_NO) AS PRIMARY_DESCRIPTION, ALT_PROD_NO, (SELECT DESCRIPTION FROM TAB2 WHERE PROD_NO=ALT_PROD_NO) AS ALT_DESCRIPTION FROM TAB1

Quote:
Originally posted by Walter Janissen
Hi

Have you tried:

SELECT PRIMARY_PROD_NO, A.description, ALT_PROD_NO,
B.Description
FROM TAB1
INNER JOIN TAB2 A
ON PRIMARY_PROD_NO = A.PROD_NO
INNER JOIN TAB2 B
ON ALT_PROD_NO = B.PROD_NO
__________________
Regards,
Adam Ac
Reply With Quote
  #5 (permalink)  
Old 03-05-04, 03:51
Walter Janissen Walter Janissen is offline
Registered User
 
Join Date: Nov 2003
Location: Germany
Posts: 62
Hi adam_ac

Your version is not possible for DB2 z/OS up to Version 7. V8 supports this syntax, but only if the select in the select list returns a scalar value.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On