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 

select question

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


Joined: 10 Oct 2006
Posts: 12
Topics: 5

PostPosted: Thu Jan 25, 2007 9:22 am    Post subject: select question Reply with quote

Hi, all.

Sorry for bothering you with a simple question but it really confused me.
Can you please help me with it?
I have some table, one of this table's columns contains some set of values.
I need to select all the rows where this column's value equals to some max values.
For ex.
Code:

column1 
---
3
5
2
3
6
6
1
4
5

I need all the rows where column1=6 or =5 or =4, that is = one of three max values.
On aix (UDB DB2 8 ) it is not a problem:
Code:

SELECT A.*                                   
  FROM table1 A                             
     , (SELECT DISTINCT column1 AS c1     
          FROM table1                       
          ORDER BY 1 DESC                   
          FETCH FIRST 3 ROWS ONLY ) C       
 WHERE A.column1 = C.c1                   

But on mvs (db2 7.1) it looks like I cannot specify order and/or fecth first in subquery.

Does some way exist on mvs to do what I need?

Thanks in advance.

Anta
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jan 25, 2007 10:20 am    Post subject: Reply with quote

Anta,

Since your table has duplicates here is a way to get the desired results

Code:

SELECT *
  FROM Table1
 WHERE col1 >= (SELECT MAX(col1)
                   FROM table1
                  WHERE col1 < (SELECT MAX(col1)
                                   FROM table1
                                  WHERE col1 < (SELECT MAX(col1)
                                                   FROM Table1)))     
 ORDER BY col1 DESC
  ;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Anta
Beginner


Joined: 10 Oct 2006
Posts: 12
Topics: 5

PostPosted: Fri Jan 26, 2007 3:16 am    Post subject: Reply with quote

Kolusu,

thank you a lot!
It really helped.
You saved me again.

Thank you once more.

With kind regards,
Anta
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