View previous topic :: View next topic |
Author |
Message |
Anta Beginner
Joined: 10 Oct 2006 Posts: 12 Topics: 5
|
Posted: Thu Jan 25, 2007 9:22 am Post subject: select question |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Jan 25, 2007 10:20 am Post subject: |
|
|
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 |
|
 |
Anta Beginner
Joined: 10 Oct 2006 Posts: 12 Topics: 5
|
Posted: Fri Jan 26, 2007 3:16 am Post subject: |
|
|
Kolusu,
thank you a lot!
It really helped.
You saved me again.
Thank you once more.
With kind regards,
Anta |
|
Back to top |
|
 |
|
|