开发者

Access query: Group get latest

开发者 https://www.devze.com 2023-03-04 08:35 出处:网络
I have a query where sometimes it may return more than one record, when this happens I just need the latest record according to the Instance field (TinyInt).

I have a query where sometimes it may return more than one record, when this happens I just need the latest record according to the Instance field (TinyInt). Trying to create the query where it executes first the query and THEN the group query. That way if it just returns one it doesn’t alter the result cause that record would be the latest.

This is on a Microsoft Access 200开发者_如何学编程3 query.


Use TOP: SELECT TOP 1 field1, field2 FROM myTable ORDER BY instance DESC.
Thats the fastest way by far.


Here are a couple answers that do something like you described. If you shared a simplified data structure and what you've tried so far you might get a more direct answer.

How can I avoid this Access SQL kludge?

how to query access to select entire records given a distinct criteria


Select MIN(myinstance) as myExpression FROM mytable WHERE (myCondition)

You may use already MAX() or other functions in sql ... Even you may use Functions in Conditions as i remember


I created another query with just the Select Field1, Max(Instance) and joined to to my original query via Field1. Was having to much of a hard time trying to incorporate a subquery. I have to many joins and just kept getting syntax errors.

0

精彩评论

暂无评论...
验证码 换一张
取 消