A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Selecting records by rowID



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2010, 04:02 PM posted to microsoft.public.access.queries
Kirk P.
external usenet poster
 
Posts: 84
Default Selecting records by rowID

I've got a table of 11,000 records. Don't ask why, it's a long story, but I
need 11 queries like this:

Query 1: records 1 - 1000
Query 2: records 1001 - 2000
Query 3: records 2001 - 2000

and so on. Any way to do this?
  #2  
Old April 22nd, 2010, 04:15 PM posted to microsoft.public.access.queries
Kirk P.
external usenet poster
 
Posts: 84
Default Selecting records by rowID

Query 3: records 2001 - 3000

sorry


"Kirk P." wrote:

I've got a table of 11,000 records. Don't ask why, it's a long story, but I
need 11 queries like this:

Query 1: records 1 - 1000
Query 2: records 1001 - 2000
Query 3: records 2001 - 2000

and so on. Any way to do this?

  #3  
Old April 22nd, 2010, 04:24 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Selecting records by rowID

Access doesn't have a RowID. Do you have a field, perferrably a primary key
field, that is numbered consecutively? If not you could add an Autonumber
field and it MIGHT number the fields. However you can't depend on this as
Autonumber fields are just guarenteed to be unique IF it's the primary key
field. Consecutive numbers are not guarenteed.

If youhave something like this, you could put criteria in individual queries
such as:

1001
Between 1001 And 2000
Between 2001 and 3000

If you don't have such a field, you might get some of the records out by
sorting ascending on the primary key field and using the Top 1000. You could
then sort descending and do a Top 1000 and get the last 1000 records. However
Top will also include duplicates in the last spot show you could have more
than 1000 records if not on a primary key field.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Kirk P." wrote:

Query 3: records 2001 - 3000

sorry


"Kirk P." wrote:

I've got a table of 11,000 records. Don't ask why, it's a long story, but I
need 11 queries like this:

Query 1: records 1 - 1000
Query 2: records 1001 - 2000
Query 3: records 2001 - 2000

and so on. Any way to do this?

  #4  
Old April 22nd, 2010, 05:21 PM posted to microsoft.public.access.queries
Kirk P.
external usenet poster
 
Posts: 84
Default Selecting records by rowID

I used your Autonumber idea and that worked fine for this purpose. Thanks!

"Jerry Whittle" wrote:

Access doesn't have a RowID. Do you have a field, perferrably a primary key
field, that is numbered consecutively? If not you could add an Autonumber
field and it MIGHT number the fields. However you can't depend on this as
Autonumber fields are just guarenteed to be unique IF it's the primary key
field. Consecutive numbers are not guarenteed.

If youhave something like this, you could put criteria in individual queries
such as:

1001
Between 1001 And 2000
Between 2001 and 3000

If you don't have such a field, you might get some of the records out by
sorting ascending on the primary key field and using the Top 1000. You could
then sort descending and do a Top 1000 and get the last 1000 records. However
Top will also include duplicates in the last spot show you could have more
than 1000 records if not on a primary key field.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Kirk P." wrote:

Query 3: records 2001 - 3000

sorry


"Kirk P." wrote:

I've got a table of 11,000 records. Don't ask why, it's a long story, but I
need 11 queries like this:

Query 1: records 1 - 1000
Query 2: records 1001 - 2000
Query 3: records 2001 - 2000

and so on. Any way to do this?

  #5  
Old April 22nd, 2010, 05:55 PM posted to microsoft.public.access.queries
Clifford Bass via AccessMonster.com
external usenet poster
 
Posts: 150
Default Selecting records by rowID

Hi Kirk,

There is another method that does not require a new field. This example
gets groups of 100 records from a major codes table:

For records 1-100:

SELECT MAJOR_CODE, MAJOR_DESCRIPTION
FROM MAJOR_CODES
WHERE MAJOR_CODE Between
(select Max(MAJOR_CODE)
from
(select Top 1 MAJOR_CODE
from MAJOR_CODES
order by MAJOR_CODE))
And
(select Max(MAJOR_CODE)
from
(select Top 100 MAJOR_CODE
from MAJOR_CODES
order by [MAJOR_CODE]));

For records 101-200 simply change the "Top n" values in each subselect:

SELECT MAJOR_CODE, MAJOR_DESCRIPTION
FROM MAJOR_CODES
WHERE MAJOR_CODE Between
(select Max(MAJOR_CODE)
from
(select Top 101 MAJOR_CODE
from MAJOR_CODES
order by MAJOR_CODE))
And
(select Max(MAJOR_CODE)
from
(select Top 200 MAJOR_CODE
from MAJOR_CODES
order by [MAJOR_CODE]));

And so on... In this case MAJOR_CODE is the only key field. It gets a
bit more complicated if you have compound keys.

Clifford Bass

Kirk P. wrote:
I've got a table of 11,000 records. Don't ask why, it's a long story, but I
need 11 queries like this:

Query 1: records 1 - 1000
Query 2: records 1001 - 2000
Query 3: records 2001 - 2000

and so on. Any way to do this?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201004/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.