I am making some paging, and I need to make some query and get the result form defined slicing . for example: I need to get all "top" rows in range 20n < x < 40n etc.
SELECT * FROM Reflow WHERE ReflowProcessID = somenumber ORDER BY ID DESC;
and now I need to make my sliding by column called ID .
Any suggestions how to so ? I need to run my query on mysql, mssql, and oracle.
For example, TOP(10) would return the top 10 rows from the full result set. Optional. If PERCENT is specified, then the top rows are based on a percentage of the total result set (as specfied by the top_value).
Top-N Analysis in SQL deals with How to limit the number of rows returned from ordered sets of data in SQL. most records from a table based on a condition. This result set can be used for further analysis.
Assuming your page size is 20 record, and you wanna get page number 2, here is how you would do it:
SQL Server, Oracle:
SELECT * -- <-- pick any columns here from your table, if you wanna exclude the RowNumber FROM (SELECT ROW_NUMBER OVER(ORDER BY ID DESC) RowNumber, * FROM Reflow WHERE ReflowProcessID = somenumber) t WHERE RowNumber >= 20 AND RowNumber <= 40
MySQL:
SELECT * FROM Reflow WHERE ReflowProcessID = somenumber ORDER BY ID DESC LIMIT 20 OFFSET 20
In MySql, you can get 10 rows starting from row 20 using:
SELECT * FROM Reflow WHERE ReflowProcessID = somenumber ORDER BY ID DESC LIMIT 10 OFFSET 20 --Equivalent to LIMIT 20, 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With