Results 1 to 4 of 4
  1. #1
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78

    Return Top 5 in DESC Order regardless of Tie

    I am trying to return the top 5 records regardless of a tie. I am having trouble getting this to work. I have tried to use Top 5 Syntax but it doesn't suppress ties.

    The goal is to have a report with flags displaying the top 5 (as this is all that fits on the page and I don't care about ties).... I have done this before and don't recall having this issue.

    Click image for larger version. 

Name:	Examples.jpg 
Views:	13 
Size:	184.6 KB 
ID:	37860

    I have also tried using this SQL... However once the ID Count gets to the 5th record they record count hits 0.....so it will prevent me from filtering on 1 to 5...



    Code:
    SELECT (SELECT Count(t1.[CQ]) FROM [qry006-SO-HC-by-Location] t1 WHERE t1.[CQ]<t2.[CQ]) AS RowID, T2.Location, T2.Flag, T2.CQ, T2.LY, T2.[Pct Change], T2.Arrow
    FROM [qry006-SO-HC-by-Location] AS T2
    ORDER BY T2.CQ DESC;




    Click image for larger version. 

Name:	Examples2.jpg 
Views:	13 
Size:	179.8 KB 
ID:	37861


    Any help solving this issue would be much appreciated. Here is what the report looks like for reference (I set the columns to 5):

    Click image for larger version. 

Name:	Examples3.jpg 
Views:	13 
Size:	16.6 KB 
ID:	37862

  2. #2
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    I just created a new query based on the previous query and then used top 5 syntax. Seemed to work without issue. Seems pretty odd to me..... can anyone help to explain how the database is logically processing this stuff?

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I don't do a lot with this kind of thing...but instead of running a simple Select query couldn't you run a Select Unique query...then run you do the TOP 5 thing?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    Hey Missinglinq-

    I initially tried to do SELECT DISTINCT as you referenced and I still got the same results. Glad I was able to figure out a workaround. I appreciate your input.

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

Similar Threads

  1. Replies: 8
    Last Post: 03-20-2018, 11:30 AM
  2. Order By DateField... ASC if this / DESC if that
    By MatthewGrace in forum Queries
    Replies: 7
    Last Post: 12-15-2015, 03:30 PM
  3. Replies: 4
    Last Post: 10-10-2015, 05:09 PM
  4. Replies: 9
    Last Post: 07-21-2015, 05:29 AM
  5. ORDER BY error when using DESC in an IIf
    By Smitoris in forum Queries
    Replies: 2
    Last Post: 10-30-2011, 02:48 AM

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