Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2006

Tip: Looking for answers? Try searching our database.

Return every nth record? - newbie

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
notv788 - 24 Mar 2006 16:47 GMT
Hello.

I am trying to get a result of returning every 4th record in a database of
thousands.

Not sure how to go about the process?
Allen Browne - 24 Mar 2006 17:19 GMT
In order for "every 4th record" to be meaningful, you must have a primary
key that defines uniquely defines the order of records.

For this example, we will assume it is an AutoNumber named ID, and the table
is named Table1.

You could get a counter in your query by typing a subquery such as this into
a fresh column of the Field row in query design:
   (SELECT Count(ID) FROM Table1 AS Dupe WHERE Dupe.ID <= Table1.ID)

To get every 4th record, use Mod 4. The expression in the Field row is
therefore:
   (SELECT Count(ID) FROM Table1 AS Dupe WHERE Dupe.ID <= Table1.ID) Mod 4
In the Criteria row, enter:
   0
Uncheck the Show box in query design. (Results will be read-only if you do
not clear this box.)

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hello.
>
> I am trying to get a result of returning every 4th record in a database of
> thousands.
>
> Not sure how to go about the process?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.