I wanted to set the number rows returned per query say 5. How can I set this in the sql query. Can any one please help me
Asked
Active
Viewed 3,389 times
0
-
2Which DBMS ? MySQL ? MSSQL ? Oracle ? – Raptor Jun 06 '14 at 07:51
4 Answers
1
Highly dependent on what RDBMS you are using.
For Oracle
SELECT * FROM the_table WHERE ROWNUM < 6
(since 12c there is another option, too).
For Postgresql
SELECT * FROM the_table LIMIT 5
0
As someone suggest zou can use:
select top X from table_name
where X is the numer of rows that you want
or you can use row_number
With cte AS
( SELECT *,
ROW_NUMBER() OVER (order by table_column) as RowNumber
FROM table_name)
select *
from cte
Where RowNumber <= 5
or even:
With cte AS
( SELECT *,
ROW_NUMBER() OVER (order by table_column) as RowNumber
FROM table_name)
select *
from cte
Where RowNumber between 5 and 10

sdrzymala
- 387
- 1
- 10