Results 1 to 6 of 6
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Selecting TOP 3 in one field is not working properly

    In the attached DB, I some SQL code in a query which is selecting the TOP 3 of the field, TimesheetDate. As I understand it, this should select the top 3 rows right? But the query results do not show 06/17/2014, 06/18/2014 and 07/08/2014 in that order like the table does.

    Why isn't the query results showing the top 3 rows?
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You need to add a sort to the query on the field you want the top 3 values for.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by pbaldy View Post
    You need to add a sort to the query on the field you want the top 3 values for.
    Thank you for your reply. I tried this:

    Code:
    SELECT TOP 3 TimesheetDate
    FROM Timesheet
    ORDER BY TimesheetDate;
    and I still didn't get the expected results. Any suggestions?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Worked for me. What result did you get?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by pbaldy View Post
    Worked for me. What result did you get?
    Ok now it worked.

    1. Is the TOP clause designed to give you the 3 greatest values or the first 3 values that appear?

    2. Also what about this? My table data for the timesheet field appears as: 6/16/, 6/17 and 10/28. What would I have to do in order to retrieve those 3 values in that exact order? I thought that was what the TOP clause was supposed to do?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Heading out to a friend's for dinner, but the 7 record would come before the 10 record. The TOP predicate will give you the first 3 records based on the sort order.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. accde file not working properly
    By joshynaresh in forum Database Design
    Replies: 9
    Last Post: 10-28-2013, 04:42 AM
  2. Checkboxes not working properly
    By TK03 in forum Access
    Replies: 1
    Last Post: 12-24-2012, 09:04 AM
  3. Update Query Not Working Properly !
    By hamxa7 in forum Queries
    Replies: 3
    Last Post: 09-20-2012, 04:58 PM
  4. NotInlist Event not working properly
    By thanosgr in forum Programming
    Replies: 2
    Last Post: 06-14-2012, 01:46 PM
  5. Delete SQL statement not working properly
    By Alexandre Cote in forum Programming
    Replies: 3
    Last Post: 10-18-2010, 12:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums