is it possible to select the 5th record until the 30th record in a sql query?
Printable View
is it possible to select the 5th record until the 30th record in a sql query?
Not sure if there is a shortcut.
I would load the query into a datatable and iterate through the datatable as follows:
VB Code:
Dim str As String Dim myDataTable As New DataTable 'Populate your datatable with all rows For i = 4 to 29 'row numbers 5 to 30 'assign the value of the first field in row i to str str = myDataTable.Rows(i).Item(0) Next
i know that, i am just asking on the sql part if it is possible?
Check out the top method not sure if you can amend that?
SELECT *
FROM (Select top 30 * from Products) where productID > 4;
Did it work??
it did work. Try it on your Northwind database. it will work:-0
Glad i could help! ;)
It will work provided that a product with ProductID between 1 and 4 (inclusive) has not been deleted. If this is the case, then ProductID 5 can at most be the fourth record and should be excluded but will not be excluded according to the WHERE clause above.Quote:
Originally Posted by iehjsucker
You could populate a datatable with "Select top 30 * from Products" then:
to remove the first 4 rows.VB Code:
For i = 0 to 3 myDataTable.Rows.RemoveAt(i) Next