Getting bottom N records from table (as opposed to TOP N)

V

VMI

How can I get the bottom N records from an Access table?
For example, if I want to display records 151-200 (with ID as PK), my query
would be:

"select top 50 * from audit where ID > 150 order by ID asc"

Since ID is type AutoNumber, I'll see records 151-200. But once I'm
displaying them, how can I go back to seeing 101-150? I tried:

"select top 50 * from audit where ID <= 150 order by ID desc" and it'll show
me the correct data, but from 150-101.

Thanks.
 
R

Rick Brandt

VMI said:
How do you mean?
It's already sorted by descending.

A TOP query sorted one way is identical to a BOTTOM query sorted the
opposite way. Since there is no BOTTOM clause available, you have to
reverse the sort and use TOP.
 
V

VMI

That's what I do:

select top 50 * from audit where ID > 150 order by ID desc

but I get an incorrect result. I get the last 50 records of the table .
 
R

Rick Brandt

VMI said:
That's what I do:

select top 50 * from audit where ID > 150 order by ID desc

but I get an incorrect result. I get the last 50 records of the table .

If newer records have a higher ID (usually the case) then if you sort the
IDs in descending order the newest ones will be at the top. If that's not
what you want then sort Ascending on ID. One of them should be what you
want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top