Always thought
AccessThe SQL statement of is similar to that of SQL Server.
TopN in
AccessAll tests were successful, but we suddenly found out yesterday
AccessThere is
Problem:
If
TopThe statement is followed by order by, and the order by field contains duplicate values, then this
TopIt is likely to become invalid,
All records are returned.
For example, select
Top5 from news order by createdate
If there are duplicate values in createdate, it is very likely that all records will be displayed.TopFunction will be invalid
However, if no duplicate value exists in createdateTopThe function is valid.
ThereforeAccessUsed inTopThe function must pay attention to whether the order by field has repeated values. If createdate is like "year-month-day hour: minute: Second", it is basicallyProblemNot big.
But for the sake of insurance, we can also use the "add primary key" method:
Select
Top5 from news order by createdate DESC, Id DESC
This can be prevented by using the primary key as a "non-repeating" safeguard.ProblemYes !!
Hope this is useful to some friends !!
Find an explanation on the Internet:
Jet SQL is not a T-SQL statement.
Jet SQL returns a duplicate value, that is, if the order by field in a table is 0, there are a total of 100 records, even if you use selectTop1 to return records, and 100 records are also returned, because Jet DB cannot judge the order in these 100 records, and only 100 records can be returned. To solve this problemProblemYou can add a primary key field.