MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problem with UNION

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
pzmohanty
Beginner


Joined: 20 May 2004
Posts: 97
Topics: 43
Location: hyderabad, India

PostPosted: Sun Sep 05, 2004 8:22 am    Post subject: problem with UNION Reply with quote

hi all,

I am facing a problem with UNION clause :

i have a following query----

SELECT COMMISSION,EMP_ID FROM EMPLOYEE
WHERE COMMISSION = 0 FETCH FIRST ROW ONLY
UNION
SELECT COMMISSION,EMP_ID FROM EMPLOYEE
WHERE COMMISSION = 100 FETCH FIRST ROW ONLY ;

The error message i got is following:

DSNT408I SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD UNION, TOKEN
<END-OF-STATEMENT> WAS EXPECTED
DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 0 0 0 -1 147 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000000' X'00000000' X'00000000' X'FFFFFFFF'
X'00000093' X'00000000' SQL DIAGNOSTIC INFORMATION

How else can i get the desired result??

Following is the requirement :

The EMPLOYEE table has various columns , 2 of them are EMP_ID & COMMISSION.
EMP_ID is primary key.
in the table there are many employees have commission of 0 & 100.
there are other employees too had commissions other than 0 & 100.

I have to query EMP_ID & COMMISSION of one employee each for employee getting commission 0 & employee getting commission 100.

Thanx in advnc
P.R.Mohanty
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
pzmohanty
Beginner


Joined: 20 May 2004
Posts: 97
Topics: 43
Location: hyderabad, India

PostPosted: Mon Sep 06, 2004 6:14 am    Post subject: Reply with quote

hi all,

one way i found to get around the problem is to use following query :

SELECT EMP_ID , COMMISSION FROM EMPLOYEE
WHERE EMP_ID = ( SELECT MAX(EMP_ID) FROM EMPLOYEE WHERE COMMISSION = 0 )
UNION
SELECT EMP_ID , COMMISSION FROM EMPLOYEE
WHERE EMP_ID = ( SELECT MAX(EMP_ID) FROM EMPLOYEE WHERE COMMISSION = 100 )

but I believe this is CPU hungry quey;

Is there any better query ???

Thanx ,
P.R.Mohanty
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
a_seshu
Beginner


Joined: 30 Sep 2004
Posts: 16
Topics: 4
Location: Chennai

PostPosted: Fri Oct 01, 2004 11:39 pm    Post subject: A better way of coding the SQL for your requirement. Reply with quote

This would be a CPU friendly SQL Smile

Code:
 SELECT EMP_ID , COMMISSION FROM EMPLOYEE
WHERE EMP_ID IN ( SELECT MAX(EMP_ID) FROM EMPLOYEE GROUP BY COMMISSION HAVING COMMISSION IN (0,100))


Worked fine when i did a quick run in Oracle. I am sure it would fare well in DB2 too. Wink
_________________
I dont think I would ever stop learning. - Seshu.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group