Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 27th, 2003, 04:37 PM
RandyL712 RandyL712 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2002
Posts: 548 RandyL712 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 19 sec
Reputation Power: 0
MS Access - limit results to 5 results?

What's the easiest way to limit the number of results in a MS ACCESS query?

Reply With Quote
  #2  
Old May 27th, 2003, 04:45 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
In the query properties or on the Query Design toolbar, change the Top Values property from "All" to 5.

You can limit the resultset to either a hardcoded count or a percentage.

Reply With Quote
  #3  
Old May 27th, 2003, 04:58 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
I think we're talking apples and oranges here. When I run a query, I get back the records that meet that query's criteria. What are "RESULTS" if they're not records. I must be misunderstanding exactly what you're trying to do.

Reply With Quote
  #4  
Old May 27th, 2003, 05:20 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
I opened a query on a table with 3935 records. I set the Top Value = 5. No matter how I changed the range on my WHERE clause, it always returned 5 records from within that range. Obviously it was looking at the whole table, not the first 5 records.

If Top Value only looked at the first 5 records, this would be a totally useless feature on a table of any substantial size. The probability that you would find the records that matched your query's WHERE clause in the first 5 records is about nil. Also, the only way to guarantee that records will always return from a query in a particular order is by using an ORDER BY clause. The concept of "the first 5 records" in a table doesn't necessarily make sense since you have no way of knowing which order the database engine has stored the records on the disk.

According to the documentation and the way it works on my machine, Top Value is the feature you're looking for. I don't know why it isn't working that way on your machine.

Documentation:
You can use the TopValues property to return a specified number of records or a percentage of records that meet the criteria you specify. For example, you might want to return the top 10 values or the top 25 percent of all values in a field.

Reply With Quote
  #5  
Old August 14th, 2003, 03:48 PM
Kim Dolan Kim Dolan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 1 Kim Dolan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Specifying between top records & values

When running a query using the SELECT TOP

SELECT TOP 5000 [cons 5k 6-10].[Acct Nbr], [cons 5k 6-10].[MaxOfShipped Ord], [cons 5k 6-10].[MaxOfShipped Rev]
FROM [cons 5k 6-10] LEFT JOIN [cons 5k 6] ON [cons 5k 6-10].[Acct Nbr] = [cons 5k 6].[Acct Nbr]
WHERE ((([cons 5k 6].[Acct Nbr]) Is Null))
ORDER BY [cons 5k 6-10].[MaxOfShipped Rev] DESC;

The query results will often receive anywhere from 5,000 to 5,045 records as it breaks at 5,000 VALUES not 5,000 RECORDS (record = row).

How do I pull only 5,000 records while using SELECT TOP? It is required to have both elements in the query: SELECT TOP and a record maximum/limit.

Thanks!

Reply With Quote
  #6  
Old August 15th, 2003, 11:52 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
If you take the TOP 5000 out of the query do you get the results you're looking for? In other words, since you're sorting the data in descending order and limiting the query to 5,000 records shoudn't this give you the top records even with the TOP 5000 removed from the query?

I'm not at a computer where I can test this so I don't know if it is going to sort the data descending first and then give you 5000 records (correct results) or if it is going to take 5000 records and then sort them in descending fashion (incorrect results).

This is just a guess so let me know if it doesn't work.

Reply With Quote
  #7  
Old August 15th, 2003, 10:47 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
you are correct, sort by desc to get TOP x highest values.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > MS Access - limit results to 5 results?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway