本文介绍了用于限制Access 2000中检索的详细信息数量的SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hello All, 如何使用SQL限制在Master-Detail集中选择的详细记录数? I想要选择日期的所有主记录,但只选择前3个记录的详细信息(基于详细记录的主键)。我已经用TOP 3尝试了,但是无法到达任何地方。使用Access 2000. 类似于: SELECT t1。*,TOP 3 t2。* FROM t1,t2 WHERE(t1.item = t2.item)AND(t1.TrnDate =#09/23/06#) 任何帮助表示感谢, Hexman Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details (based on the primary key of the detail record). I''vebeen trying with "TOP 3", but can''t get anywhere. Using Access 2000. Something like: SELECT t1.*, TOP 3 t2.*FROM t1, t2WHERE (t1.item = t2.item) AND (t1.TrnDate = #09/23/06#) Any help appreciated, Hexman推荐答案 使用SQL设置Master-Detail? Master-Detail set using SQL? 详细记录(基于详细记录的主键)。 我已经 records for the details (based on the primary key of the detail record).I''ve 在优化之前你需要了解你在做什么:) 现在,您正在创建一个数据集,该数据集有效地为t1中的每个条目创建t2中所有 记录的副本。如果你有很多记录,这个 会非常快速地得到你的手(即2个表每个1000条记录 会以这种方式在内存中产生10.000条记录)所以使用像Izzy一样的加入 建议通常要好得多。 这个怎么样: 选择* 来自t1内部联接t2(t1.item = t2.item) 其中t1.TrnDate =#09/23/06# 和t2.item in (从t2中选择前3项) 这应该加入2个表格,其中2个表格中的项目匹配并且 t1中的日期是指定的日期,项目出现在 t2的前3位。 t2没有排序顺序,因此结果可能无法预测。 - Rinze van Huizen C-Services Holland bv You need to understand what you''re doing before you can optimize it :)Now you''re creating a dataset that effectively creates a copy of allrecords in t2 for each entry in t1. If you have alot of records, thiswill get ouf of hand very quickly (i.e. 2 tables with 1000 records eachwill cause 10.000 records in memory this way) So using a join like Izzysuggested is usually much better. How about this: Select *from t1 inner join t2 on (t1.item=t2.item)where t1.TrnDate=#09/23/06#and t2.item in(select top 3 item from t2) This should join the 2 tables where the ''item'' in the 2 tables match andthe date in t1 is the one specified and the items appear in the top 3 oft2. There is no sort order given to t2, so results may be unpredictable.--Rinze van HuizenC-Services Holland b.v 这篇关于用于限制Access 2000中检索的详细信息数量的SQL语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 22:39