A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

select top



 
 
Thread Tools Display Modes
  #1  
Old June 24th, 2009, 04:41 PM posted to microsoft.public.access.gettingstarted
Striker
external usenet poster
 
Posts: 47
Default select top

What is the best way to select the top 5 records from a field configured as
DATE/TIME in Access 2007? I know I can select * and order by, to get the
last records. I only need the last 5 by the date they were added to the
table.

Thanks

  #2  
Old June 24th, 2009, 04:52 PM posted to microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default select top

"Striker" wrote in message
...
What is the best way to select the top 5 records from a field configured
as DATE/TIME in Access 2007? I know I can select * and order by, to get
the last records. I only need the last 5 by the date they were added to
the table.



If I understand you correctl, the query would be along these lines:

SELECT TOP 5 * FROM [MyTable]
ORDER BY [MyDateTimeField] DESC

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #3  
Old June 24th, 2009, 05:26 PM posted to microsoft.public.access.gettingstarted
Striker
external usenet poster
 
Posts: 47
Default select top

OK, so it's the same as SQL. I was doing that as a select top 10. it kept
returning 16 records. I did notice some of the dates were the same on the
records however.


"Dirk Goldgar" wrote in message
...
"Striker" wrote in message
...
What is the best way to select the top 5 records from a field configured
as DATE/TIME in Access 2007? I know I can select * and order by, to get
the last records. I only need the last 5 by the date they were added to
the table.



If I understand you correctl, the query would be along these lines:

SELECT TOP 5 * FROM [MyTable]
ORDER BY [MyDateTimeField] DESC

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


  #4  
Old June 24th, 2009, 05:33 PM posted to microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default select top

"Striker" wrote in message
...
OK, so it's the same as SQL. I was doing that as a select top 10. it
kept returning 16 records. I did notice some of the dates were the same
on the records however.



The TOP predicate makes no attempt to distinguish among records that have
the same value in the ORDER BY field(s). It returns them all. If you need
to return exactly 5 (or whatever), you can include the table's primary key
as a second ORDER BY field. Of course, then you have to understand that
your "top 5" aren't really an exclusive set.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 




Thread Tools
Display Modes

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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:03 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.