SQL only return range of records

Is there sql to only return back a range of records i.e from 20-30 in access.  or are there any easy work arrounds to this problem

thanks

dave
david_88Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
cr4ck3rj4ckConnect With a Mentor Commented:
In MySQL you can use the LIMIT function but in MSACCESS you have to use a sub query to create an offset.

select top X * from myTable where id not in (select top Y * from myTable)

X would be replaced by the amount of records you wanted to return.
Y would be replaced by the position within the data set at which you wanted to start.
id would be your unique identifier within the table.

For example:
select top 10 * from myTable where id not in (select top 19 * from myTable)

That would return records 20-30 in a recordset.
0
 
tbsgadiCommented:
Hi david_88,

Something like
SELECT * FROM Table1 WHERE ((Table1.ID) Between 20 And 30);

Good Luck!

Gary
0
 
eridanixCommented:
Hi,

this is example of SQL paging. You can simply modify it as you need:

top_onPage = "TOP " + Convert.ToString((onPage * page > totalCount) ? (totalCount % onPage) : (onPage));
top_page = "TOP " + Convert.ToString(onPage * page);

SELECT * FROM (
      SELECT TOP " + top_onPage + " id  FROM (
            SELECT DISTINCT " + top_page + " T.id
                  FROM dbo.tblTest T
            )      as A ORDER BY X ASC
)      as B ORDER BY X DESC
0
 
david_88Author Commented:
perect  thanks!
0
All Courses

From novice to tech pro — start learning today.