Results 1 to 5 of 5
  1. #1
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110

    Exclude TOP N records from query

    I have a table that includes a date/time field. I want to query that table and show all but the TOP N records. Since the number of records will always be changing I cant do it using the BOTTOM N records.

    Any suggestions on how I can do this are appreciated.

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    First Create a query to get the top N values. Create a Totals query then a Union query for the final result. Someone else may know of an easier way.


    HTH

  3. #3
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Thanks. Figured it out using this link: http://www.btabdevelopment.com/ts/tbl2exclude

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Glad you got it sorted out. Good Luck With Your Project!

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I like Bob's way of doing the exclude also.

    Here's another general approach using a subquery :

    Select * from YourTable where YourDateFieldInvolved
    Not In (Select Top N X.YourDateField from YourTable as X)

    Note: There is no Bottom N. You have to use Order By in your SQL either ASCending (the deault) or DESCending to get the "lowest" or "highest" N values.

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

Similar Threads

  1. Replies: 12
    Last Post: 02-25-2014, 08:32 AM
  2. Query to exclude non matching records
    By L1882 in forum Queries
    Replies: 1
    Last Post: 04-03-2012, 08:44 AM
  3. Replies: 4
    Last Post: 10-25-2011, 10:07 PM
  4. Replies: 2
    Last Post: 10-08-2011, 06:33 PM
  5. Exclude records within same criteria
    By brooke48 in forum Queries
    Replies: 14
    Last Post: 05-15-2010, 02:15 PM

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