Strange behavior from a totals query (1 Viewer)

fmm

Registered User.
Local time
Today, 03:42
Joined
Mar 15, 2001
Messages
76
I'm having a strange problem with a totals query.

I have an address table containing (among others) the following fields:
RecID (the link with the master table),
Generation, and
id1, an autonumber field.

Every time a new record is added for a given RecID, the generation number is increased over the previous record (the 2nd record for RecID = 123 would generally get a Generation of 2).

I built the table by adding the original addresses (all with a Generation = 1), and then added revised addresses (Generation = 2).

Since I want my query to work in the general case I did not want the query tied to a specific Generation number. I created a totals query that had "Group By" in the totals line for RecID, and "Last" for every other field. The only field indexed is RecID. This has worked for me in the past.

This time it did not. The query pulled some records with Generation = 2 (good) and others with Generation = 1 (bad).

If I look at the 'bad' results, the record put in second (and I'm sure this is the case because id1 is always higher on a record with Geeration = 2 than for the record with Generation = 1) appears first.

Am I mistaken about the use of 'Last' in a totals query? I had assumed that it would give you the last record entered after the effects of any indexes had been accounted for. In other words, if there are no indexes in effect, the query would return the last record entered for each RecID.


Thanks in advance.

[This message has been edited by fmm (edited 08-13-2001).]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:42
Joined
Feb 19, 2002
Messages
43,263
Last refers to the ordinal position of a record in a set of data. If the set is not ordered, the actual "last" record is random. And even if it is ordered, if the sort key is not unique, records with equal sort key values will be in random order within their set. Remember your set theory, relational tables are unordered sets. Many people get fooled because small tables will usually maintain a consistant order. However, large tables are completely unreliable as to sequence of records unless they are sorted.

Anyway, you really should use the Max() function since what you want is the largest value, not the last value.
 

Users who are viewing this thread

Top Bottom