Solved

SQL only return range of records

Posted on 2008-10-23
4
509 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:david_88
4 Comments
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
Hi david_88,

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

Good Luck!

Gary
0
 
LVL 6

Accepted Solution

by:
cr4ck3rj4ck earned 500 total points
Comment Utility
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
 
LVL 5

Expert Comment

by:eridanix
Comment Utility
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
 

Author Closing Comment

by:david_88
Comment Utility
perect  thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now