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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:31:23+00:00 2026-05-29T11:31:23+00:00

select count(*) as count from table group by foreign_id order by count This returns

  • 0
select count(*) as count from table
group by foreign_id order by count 

This returns a number of matches for each foreign id. However what im looking for is to summarise the results.

So the result would be:

10 results grouping 1 elements
5  results grouping 2 elements
7  results grouping 7 elements
  • 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-29T11:31:24+00:00Added an answer on May 29, 2026 at 11:31 am

    Ok, got it. The title of the question expainls it better than the question itself 🙂

    You need to first know how many times each FK appears:

    select count(*) as GroupAmount from t1
    group by foreign_id
    

    Once you have this, you have to group them to get the amount of times each item appears the same way as above. This will result in:

    select GroupAmount, count(*) GroupAmountTimes from (
      select count(foreign_id) as GroupAmount from t1
      group by foreign_id
    ) as SubQuery
    group by GroupAmount
    

    See it in action here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
When we execute select count(*) from table_name it returns the number of rows. What
I have the following query: SELECT timestamp, COUNT(*) FROM table GROUP BY timestamp But
mysql> select count(*) from table where relation_title='xxxxxxxxx'; +----------+ | count(*) | +----------+ | 1291958
For example: declare @bitHaveRows bit select @bitHaveRows = count(*) from table where (predicate) Are
If I run a query such as: SELECT COUNT(*) as num FROM table WHERE
I have a table watchlist containing today almost 3Mil records. mysql> select count(*) from
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id

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.