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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:28:07+00:00 2026-06-16T00:28:07+00:00

i have 2 tables, users and follows. table follows has a column named status.

  • 0

i have 2 tables, users and follows. table follows has a column named status. I would like to count how many follows each user has grouping by the status.

The query below returns a record for each status type for each user.

SELECT users.name as user_name, f.status, count(f.id) 
FROM users
JOIN application_follows f ON f.user_id = users.id
GROUP BY users.id, f.status
ORDER BY users.id

returns something like:

user_name     status     count

mike          new         10
mike          old         5
tom           new         8
tom           old         9

but i would like something more friendly like:

user_name     new    old

mike          10      5
tom           8       9

tried using group_concat and count but didnt work. Any clues?

  • 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-16T00:28:08+00:00Added an answer on June 16, 2026 at 12:28 am
    SELECT  user_name, 
            MAX(CASE WHEN status = 'new' THEN totalFollowers ELSE NULL END) `NEW`,
            MAX(CASE WHEN status = 'old' THEN totalFollowers ELSE NULL END) `OLD`
    FROM
        (
            SELECT  users.name as user_name, 
                    f.status, 
                    count(f.id) totalFollowers 
            FROM    users
                    LEFT JOIN application_follows f 
                        ON f.user_id = users.id
            GROUP BY users.id, f.status
        ) derivedTable
    GROUP BY user_name
    

    or maybe (not sure about this one)

    SELECT  users.name as user_name, 
            MAX(CASE WHEN f.status = 'new' THEN count(f.id) ELSE NULL END) `NEW`, 
            MAX(CASE WHEN f.status = 'old' THEN count(f.id) ELSE NULL END) `OLD`
    FROM    users
            LEFT JOIN application_follows f 
                ON f.user_id = users.id
    GROUP BY users.id, f.status
    

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

Sidebar

Related Questions

i have 2 tables, users and follows. table follows has a column named status.
I have two tables, users and groups . A user can belong to many
I have two tables. The first table holds simple user data and has the
I have a table joining two models in a has many through relationship. Users
If I have two tables - Logins and Users, as follows: Logins LoginIdNo UserIdNo
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
I have 2 tables: users and subscribers . The relationship of the user to
I have a hibernate object called User which has a many-to-many relationship with another
I have two tables pertaining to this question: conversations has many messages . The

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.