Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does Access handle LIMIT statement? 1

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
I can use TOP, but that only works from the top. I need to paginate the data, say 25 records at a time. How do I do that in Access?

SELECT TOP 25 usc_Detail.* FROM usc_Detail,

but how would I fetch just records 26-50?

In SQL Server I can use LIMIT 26, 25


-Pete
Games the old fashion way with Dice, Paper and Pencils!
 
Ok, so you have this:

Code:
SELECT TOP 25 usc_Detail.* FROM usc_Detail

Now, if you want the next 25, you can do this (assumes some kind of PK value)

Code:
select top 25 usc_Detail.* from usc_Detail
where usc_Detail.PK not in (select top 25 usc_Detail.PK from usc_Detail)

One note - whenever you use TOP, specify an ORDER BY as well. Without an order by there is no guarantee you will get the same top 25 each time.

Hope this helps,

Alex

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Ahh ok so and pardon my ignorance on this,

Get the first 10
Code:
select top 10 usc_Detail.* from usc_Detail ORDER BY usc_Detail.somefield
where usc_Detail.PK not in (select top 25 usc_Detail.PK from usc_Detail)

Get the 2nd 10
Code:
select top 20 usc_Detail.* from usc_Detail ORDER BY usc_Detail.somefield
where usc_Detail.ID not in (select top 10 usc_Detail.ID from usc_Detail ORDER BY usc_Detail.somefield)

And so on?


-Pete
Games the old fashion way with Dice, Paper and Pencils!
 
one change to the second (you want next 10 not next 20):

Code:
select top 10 usc_Detail.* from usc_Detail ORDER BY usc_Detail.somefield
where usc_Detail.ID not in (select top 10 usc_Detail.ID from usc_Detail ORDER BY usc_Detail.somefield)

so 21-30 would be:
Code:
select top 10 usc_Detail.* from usc_Detail ORDER BY usc_Detail.somefield
where usc_Detail.ID not in (select top [b]20[/b] usc_Detail.ID from usc_Detail ORDER BY usc_Detail.somefield)

You only want to change the number in the subquery.

Make sense?

Hope this helps,

Alex

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top