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 > DB2 Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-24-03, 05:39
suren suren is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
DB2 Query

The following query is not working in DB2 v 6 on OS/390 . How this can be achieved without creating a view. I would like to receive the min value from two tables.

SELECT MIN(VAL1) AS VAL2 FROM (
( SELECT MIN(COL1) AS VAL1
FROM TABLE1
)
UNION
( SELECT MIN(COL1) AS VAL1
FROM TABLE2
) )
Reply With Quote
  #2 (permalink)  
Old 12-24-03, 06:00
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: DB2 Query

Providing the error messages will be helpful

Cheers
Sathyaram

Quote:
Originally posted by suren
The following query is not working in DB2 v 6 on OS/390 . How this can be achieved without creating a view. I would like to receive the min value from two tables.

SELECT MIN(VAL1) AS VAL2 FROM (
( SELECT MIN(COL1) AS VAL1
FROM TABLE1
)
UNION
( SELECT MIN(COL1) AS VAL1
FROM TABLE2
) )
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 12-24-03, 06:13
suren suren is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
Re: DB2 Query

Quote:
Originally posted by sathyaram_s
Providing the error messages will be helpful

Cheers
Sathyaram
The error message is

SQL error at or before <EMPTY> (line 5, position 8). ) UNION

When I remove the parenthesis for inner selects it gives

SQL error at or before UNION
Reply With Quote
  #4 (permalink)  
Old 12-24-03, 09:26
Lin Lin is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
Re: DB2 Query

Hi,
You may try a SQL statment like this:

SELECT MIN(VAL1) AS VAL2 FROM
(
SELECT MIN(COL1) AS VAL1
FROM TABLE1
UNION
SELECT MIN(COL1) AS VAL1
FROM TABLE2
) as T1


Quote:
Originally posted by suren
The error message is

SQL error at or before <EMPTY> (line 5, position 8). ) UNION

When I remove the parenthesis for inner selects it gives

SQL error at or before UNION

Last edited by Lin; 12-24-03 at 23:01.
Reply With Quote
  #5 (permalink)  
Old 12-24-03, 09:57
aloz aloz is offline
Registered User
 
Join Date: May 2003
Location: San Juan, PR
Posts: 18
Also, you can try next statement

SELECT CASE WHEN A < B THEN A ELSE B END
FROM (SELECT MIN(col1) A FROM table1) AS T1,
(SELECT MIN(col2) B FROM table2) AS T2

Saludos, Aloz
Reply With Quote
  #6 (permalink)  
Old 12-29-03, 04:31
suren suren is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
Hi Aloz

The query with case structure really works. That's Great !!
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