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 > Nested tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-02-07, 04:15
annamaria annamaria is offline
Registered User
 
Join Date: Apr 2007
Posts: 51
Nested tables

I have a query with several nested table.
For every selection, I have to select all the columns of the previous nested
tables plus other columns I create.
For example:

select
field1,
field2,
field1/field2 as field3
from (
select
field1, field2
from mytable.
In the real query I have many columns to select and so in order to avoid to
repeat all the fields names in every selection, I'd like to make this selection:

select
*,
field1/field2 as field3
i.e. I want to select all the columns of the previous table plus the new
created column.
How can that be done?
Thank you.
Anna - Verona (Italy)
Reply With Quote
  #2 (permalink)  
Old 06-02-07, 07:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select *
     , field1/field2 as field3
  from (
       select field1
            , field2
         from mytable
       ) as d
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-02-07, 07:42
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You will need to be using DB2 for z/OS V8.1. Common table expressions do not exist in DB2 V7 for z/OS (still supported by IBM).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 06-02-07, 15:24
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
Quote:
Originally Posted by r937
Code:
select *
     , field1/field2 as field3
  from (
       select field1
            , field2
         from mytable
       ) as d

"SELECT *" does not allow you to specify additional columns besides you use a correlation name with the *.


SELECT D.* , field1/field2 as field3
FROM (
SELECT field1 , field2
FROM my.table ) as D ;

should work.
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