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 9199089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:26:51+00:00 2026-06-17T22:26:51+00:00

Suppose now I have a table T which is like this: A|B 1|1 1|2

  • 0

Suppose now I have a table T which is like this:

A|B
1|1 
1|2 
2|1 
2|2 
2|3 
3|1 
3|2 
3|3 

With select A, count(*) from T group by A we should get:

A|count(*)
1|2
2|3
3|3

Now I need to get the last two rows in the previous query — which have the maximum value of count(*). How can I do this in a single query?

Thanks.

  • 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-06-17T22:26:53+00:00Added an answer on June 17, 2026 at 10:26 pm
    WITH recordList
    AS
    (
        SELECT  A, COUNT(*) totalCount,
                DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) rn
        FROM    tableName
        GROUP BY A
    )
    SELECT  A, totalCount
    FROM recordLIst
    WHERE rn = 1
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an SQL table entitled Facility which looks like this: || FacilityID
Suppose i have 1kk records in my database. Now i need to select some
Suppose I have a query like this: SELECT s.staffID as staffID, CONCAT_WS(, , lname,
Suppose, I have a table like this- Code | something ------------------ C01 abc C02
this is a follow-up question of mine. Suppose now I have a URL :
Suppose I have this feature branch foo. Now I want to merge it back
Suppose I have a web application, which uses jQuery for Ajax and UI. Now
I have a sql table images which has columns id , imagePath , caption``count
Background: I have a table with 5 million address entries which I'd like to
We have a table named tags which has 3 cols: id, value, count which

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.