How to query range of data in DB2 with highest performance?

Posted by Fuangwith S. on Stack Overflow See other posts from Stack Overflow or by Fuangwith S.
Published on 2008-11-05T16:59:14Z Indexed on 2010/06/13 18:22 UTC
Read the original article Hit count: 205

Filed under:
|
|

Usually, I need to retrieve data from a table in some range; for example, a separate page for each search result. In MySQL I use LIMIT keyword but in DB2 I don't know. Now I use this query for retrieve range of data.

SELECT * 
FROM(
   SELECT  
      SMALLINT(RANK() OVER(ORDER BY NAME DESC)) AS RUNNING_NO
      , DATA_KEY_VALUE
      , SHOW_PRIORITY
   FROM 
      EMPLOYEE
   WHERE 
      NAME LIKE 'DEL%'
   ORDER BY
      NAME DESC
   FETCH FIRST 20 ROWS ONLY
) AS TMP
ORDER BY 
  TMP.RUNNING_NO ASC
FETCH FIRST 10 ROWS ONLY

but I know it's bad style. So, how to query for highest performance?

© Stack Overflow or respective owner

Related posts about sql

Related posts about database