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 

SQL QUERY

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


Joined: 28 May 2003
Posts: 51
Topics: 30

PostPosted: Mon Nov 10, 2003 7:43 am    Post subject: SQL QUERY Reply with quote

I have a table INASBU with definition as :
Code:

Column Name        Col No Col Type Length
*                  *      *        *     
------------------ ------ -------- ------
NLBKZ                   1         CHAR          1
GDAT                    2         CHAR         10
NLBID                   3         CHAR          4
NLBBEZ                  4        CHAR         60

There is no primary index on this table.Now I want to select all the distinct values. ie most recent GDAT with unique NLBKZ, NLBID and NLBBEZ
Now i have records as :
GDAT NLBID NLBBEZ
---------- ----- ---------------------------------------------------
20030531 0002
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Nov 10, 2003 8:42 am    Post subject: Reply with quote

Vani,

Try this

Code:

SELECT MAX(GDAT) FROM TABLE                       
 WHERE NLBKZ  = (SELECT DISTINCT NLBKZ FROM TABLE)
   AND NLBID  = (SELECT DISTINCT NLBID FROM TABLE)
   AND NLBEZ  = (SELECT DISTINCT NLBEZ FROM TABLE)
    ;                                                 


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vani
Beginner


Joined: 28 May 2003
Posts: 51
Topics: 30

PostPosted: Mon Nov 10, 2003 9:44 pm    Post subject: Reply with quote

Did not work
Distinct can be used only once

Any other solution?
Back to top
View user's profile Send private message
sri_naveen
Beginner


Joined: 29 Oct 2003
Posts: 10
Topics: 0
Location: Indore, India

PostPosted: Mon Nov 10, 2003 11:29 pm    Post subject: Reply with quote

Hi vani...try this..

SELECT MAX(GDAT) FROM <your table T1>, <same table T2>
WHERE T1.NLBKZ <> T2.NLBKZ
AND <same for other two>

this is a bit cumbursome...since its a full scan checking if its not equal..LI have no idea why multiple distinct dont work..which db are you using ?
_________________
Regards,
Naveen Srinivasan
Computer Sciences Corporation

--To err is human, to err again is more human--
Back to top
View user's profile Send private message Yahoo Messenger
vani
Beginner


Joined: 28 May 2003
Posts: 51
Topics: 30

PostPosted: Tue Nov 11, 2003 7:48 am    Post subject: Reply with quote

The below query worked. Thanks for all.

SELECT DISTINCT T.NLBID,T.NLBKZ,T.NLBBEZ,T.GDAT
FROM SAS1T01.INASBU T
WHERE T.GDAT = (SELECT MAX(GDAT)
FROM SAS1T01.INASBU
WHERE NLBID = T.NLBID);
Back to top
View user's profile Send private message
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