访问查询:群组获取最新
我有一个查询,有时它可能会返回多个记录,当发生这种情况时,我只需要根据实例字段(TinyInt)获取最新记录。 尝试创建查询,首先执行查询,然后执行组查询。这样,如果它只返回一个,它不会改变结果,因为该记录将是最新的。
这是一个 Microsoft Access 2003 查询。
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 2003 query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 TOP:
SELECT TOP 1 field1, field2 FROM myTable ORDER BY instance DESC
。这是迄今为止最快的方法。
Use TOP:
SELECT TOP 1 field1, field2 FROM myTable ORDER BY instance DESC
.Thats the fastest way by far.
这里有几个答案可以实现您所描述的功能。如果您共享一个简化的数据结构以及您迄今为止所尝试的内容,您可能会得到更直接的答案。
如何避免这种 Access SQL 混乱?
<一href="https://stackoverflow.com/questions/5953592/how-to-query-access-to-select-entire-records-given-a-distinct-criteria/5953760#5953760">如何查询对 select 的访问给定不同标准的整个记录
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
选择 MIN(myinstance) 作为 myExpression FROM mytable WHERE (myCondition)
您可能已经使用了 MAX() 或 sql 中的其他函数...即使您可以使用条件中的函数,我记得
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
我仅使用
Select Field1, Max(Instance)
创建了另一个查询,并通过 Field1 连接到我的原始查询。尝试合并子查询非常困难。我有很多连接并且不断出现语法错误。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.