2

I am having 25 Lacs records in table , how can i get first 10 lacs after 10 lacs and after that 5 lacs records in sql Server 2008.

Could you please help me in this?

In PL SQL i do like this

SELECT * FROM temp WHERE rownum > or rownum < 10

Please suggest.

Manoj Wadhwani
  • 1,487
  • 4
  • 20
  • 23
  • 1
    It depends on the DB that you use – Kayser Mar 02 '12 at 13:36
  • possible duplicate of [LIMIT / OFFSET in Oracle 11G](http://stackoverflow.com/questions/7326885/limit-offset-in-oracle-11g) – Lukas Eder Mar 02 '12 at 13:38
  • You're looking for a way to handle `LIMIT / OFFSET` (or similar clauses from other databases) in Oracle. See this question for details: http://stackoverflow.com/questions/7326885/limit-offset-in-oracle-11g, or this one: http://stackoverflow.com/questions/7480243/sql-oracle-order-by-and-limit – Lukas Eder Mar 02 '12 at 13:38
  • @Kayser: The keywords `PL / SQL` and `ROWNUM` can only be Oracle – Lukas Eder Mar 02 '12 at 13:40

2 Answers2

4
SELECT * FROM 
(
SELECT ROW_NUMBER() OVER (ORDER BY [dataKeyColumnName]) AS RowNo, * FROM Temp 
) AS A
WHERE A.RowNo BETWEEN 10 AND 15
Kaf
  • 33,101
  • 7
  • 58
  • 78
1

It depends on the DB that you use.

For Oracle you can use

SELECT * FROM(
   SELECT ROW_NUMBER() OVER (ORDER BY [tableId]) AS RowNr, * FROM MyTable 
) AS T
WHERE T.RowNr BETWEEN 6 AND 15

See also the discussion : LIMIT / OFFSET in Oracle 11G

For MYSQL you can use

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15
Community
  • 1
  • 1
Kayser
  • 6,544
  • 19
  • 53
  • 86