Quote:
|
Originally Posted by ps_deep
how to get 10 max values from a table in Db2
|
For the 10 max values of column k of table t:
Code:
SELECT DISTINCT k FROM t
ORDER BY k DESC
FETCH FIRST 10 ROWS ONLY
OPTIMIZE FOR 1 ROW
The "standard SQL" way to obtain this would be:
Code:
SELECT t1.k FROM t AS t1, t AS t2
WHERE t1.k <= t2.k
GROUP BY t1.k
HAVING count(*) <= 10