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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:41:05+00:00 2026-06-12T08:41:05+00:00

I have these three (simplified) tables for a contest application: **user** user_id **contest** contest_id

  • 0

I have these three (simplified) tables for a contest application:

**user**
user_id    

**contest**
contest_id

**contest_entry**
contest_id
user_id

There are several contests, and each user can enter each contest once (creating a contest_entry record).

Thus far there have been 5 contests, so I’d like to get a count of how many users have entered 0, 1, 2, 3, 4, or 5 contests. An example of the format I’m looking for is this:

num_contests_entered      num_users
0                         102
1                         87
2                         345
3                         254
4                         567
5                         489

I am completely stumped on the SQL needed to achieve this, so any help is greatly appreciated!

Best,
Chris

EDIT: To clarify, an example of what I am looking for is

102 users entered 0 contests
87 users entered 1 contest
345 users entered 2 contests 

etc..

  • 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-12T08:41:06+00:00Added an answer on June 12, 2026 at 8:41 am

    You can write:

    SELECT num_contests_entered,
           COUNT(1) num_users
      FROM ( SELECT COUNT(ce.contest_id) num_contests_entered
               FROM user u
               LEFT
              OUTER
               JOIN contest_entry ce
                 ON ce.user_id = u.user_id
              GROUP
                 BY u.user_id
           ) t
     GROUP
        BY num_contests_entered
     ORDER
        BY num_contests_entered
    ;
    

    The subquery finds, for each user, how many contests they entered; the outer query groups users by that count, thereby determining the number of users that entered that many contests.

    (Disclaimer: not tested.)

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

Sidebar

Related Questions

I have three tables - Context, Session and User. And below are their simplified
I have three tables (lots in reality but these three are the ones I
I have three MYSQL tables, simplified, with following columns: ModuleEntries (MDE_ID) ModuleFields (MDF_ID, MDF_Label)
I have these three lists with the same number of elements List<String>competitoinsIDs = new
Let us suppose i have these three methods defined: int F1(int, int); int F1(float,
In a rails 3 app I'm building I have these three classes: class Instrument
I have two nsbuttons in my interface builder.For all of these three nsbuttons I
I have a view from which I am selecting three columns. Of these three
I have 3 function in my class B. These three function have to access
I have three arrays and I have copied all these arrays into a single

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.