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 > error while trying to query a union of SQLs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-03, 02:00
krajkumar6 krajkumar6 is offline
Registered User
 
Join Date: Sep 2003
Posts: 9
error while trying to query a union of SQLs

Hi,

I am working on DB2 on AS 400
V5R1M0 010525 .
I have a SQL which looks like this.
In this query the union portion alone works fine.


select * from
(
select
T1.C1,T2.C2
from
T1,T2
where
....
group by
...

UNION ALL

select T3.C1,T2.C2

from
T3,T2
where
....
GROUP BY
....
) test

But when I try to select * from the union I get the
error

SQL0199] Keyword UNION not expected. Valid tokens: ). Cause . . . . . : The keyword UNION was not expected here. A syntax error was detected at keyword UNION. The partial list of valid tokens is ). This list assumes that the statement is correct up to the unexpected keyword. The error may be earlier in the statement but the syntax of the statement seems to be valid up to this point. Recovery . . . : Examine the SQL statement in the area of the specified keyword. A colon or SQL delimiter may be missing. SQL requires reserved words to be delimited when they are used as a name. Correct the SQL statement and try the request again.

Can someone tell me how this error can be overcome?

K Rajkumar

Last edited by krajkumar6; 10-13-03 at 02:17.
Reply With Quote
  #2 (permalink)  
Old 10-13-03, 02:10
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Why do you need the select *?

All you need is:

select
T1.C1,T2.C2
from
T1,T2
where
....
group by
...

UNION ALL

select T3.C1,T2.C2
from
T3,T2
where
....
GROUP BY
....
Reply With Quote
  #3 (permalink)  
Old 10-13-03, 02:23
krajkumar6 krajkumar6 is offline
Registered User
 
Join Date: Sep 2003
Posts: 9
I have a requirement to use group by on the
set of rows that are returned by the union of SQLs.

I used 'Select * from ' just to explain the problem to you.
My actual requirement has a select statement with a group by
in it ,in place of 'Select * from ' .
Reply With Quote
  #4 (permalink)  
Old 10-13-03, 04:41
blom0344 blom0344 is offline
Registered User
 
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
The select over a temporary set as you are using works correctly in DB2 UDB, the same syntax in DB2 / AS400 does not work, no matter what I try with variations on the syntax. I wonder whether this is at all possible with DB2/AS400............
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
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