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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Choose every 5th record in a an Access table

Status
Not open for further replies.

hsandwick

Programmer
Sep 10, 2001
286
US
How do I select every 5th record in an Access table, please? What is the sql query? modulus ???

Thanks,

Helen
 
what do you mean fifth?

fifth where you already have a numbering system
or
any random 20% of your table?

if you already have a numbering system, then yes, you could just use the integer division mod to work out what to include

if it's just a random 20% you can use the top keyword to only include a selection from a table...

--------------------
Procrastinate Now!
 
record 5, record 10, record 15 and so on.

What clouds the situation is that I may not want to start on record one.

I don't use Access much, so would you mind providing me with the SQL statement to handle this?

Thanks.
 
yes, I realise it's record5/10/15...

the point is, how do you tell which record is record 5?

IS there a recordNumber associated with each record?

--------------------
Procrastinate Now!
 
yes, I know the issue, how do you tell which record is record 5. In a perfect world, it would start at record 5.

So, focusing on the perfect world, how would this be done?

Then, focusing on an imperfect world, let's say the record starts at 3, then every 5th record after that, how would this be done?

Yes, there is a recordNumber associated with each record.

Thanks.
 
Most Access databases do NOT have consecutive record numbers, which was Crowley16's point, I'm sure.

One way (tested)
Code:
Select * 
from tbl
where (((tbl.recordNumber mod 5) - [COLOR=red]3[/color]) = 0);
where 3 is your starting position number. Starting position must be between 0 and 4 for a set of 5. If you wanted to start further in the table, add AND tbl.recordNumber > n to your selection criteria.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top