Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:37:53+00:00 2026-05-30T05:37:53+00:00

I have a portion of my query as shown below which the TOP 1

  • 0

I have a portion of my query as shown below which the TOP 1 is supposed to be shared among 2 records as there are 2 outlets that has the same visit count. Apparently, the query will only return one record. How can I display the “accurate” output in this case?

Select TOP 1 (O.Name) as MostVisited
         From [Trans] T 
             INNER JOIN [Outlet] O
             On (T.Outlet_Code = O.Code)

      Where [VoidBy] IS NULL AND [VoidOn] IS NULL AND CardNo In     
            (Select [CardNo] From [Card] Where [CardNo] = 'CARDX' AND [MemberID] = @MemberId)
      Group by O.Name     
      Order by Count(T.Outlet_Code) Desc   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:37:55+00:00Added an answer on May 30, 2026 at 5:37 am
    Select TOP (1) WITH TIES (O.Name) as MostVisited
           ....
    

    WITH TIES provides for “joint top” situations.

    Example:

    DECLARE @t TABLE (foo int, qty int);
    INSERt @t VALUES (1, 100), (3, 200), (2, 200);
    
    -- one row, arbitrary
    SELECT TOP (1) * FROM @t ORDER BY qty DESC;
    
    -- both rows with "TOP 1 value"
    SELECT TOP (1) WITH TIES * FROM @t ORDER BY qty DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: we have one application that has a portion which is used by
I have a query (portion of it) like this below, when my GridView is
We have a large-ish query here that has several params, and for each one,
I am building a site that will (obvisouly) have a front end public portion
I have a long LinqtoSQl query in which several parameters I'm not forcing the
I have two tables, one has about 1500 records and the other has about
Below is part of a library that generates lists of models.... the ->getBy() portion
I have a site that treats / and %2F in the path portion (not
I have a hopefully simple MySQL query question which is eluding me at late
I have an archive page template that I've built that has a successful navigation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.