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

  • Home
  • SEARCH
  • 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 146251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:34:08+00:00 2026-05-11T08:34:08+00:00

In the simple case, assume I have a table that looks like this: mysql>

  • 0

In the simple case, assume I have a table that looks like this:

mysql> describe widget;  +---------+--------------+------+-----+---------+-------+ | Field   | Type         | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name    | varchar(255) | YES  |     | NULL    |       |  | enabled | smallint(1)  | YES  |     | NULL    |       |  +---------+--------------+------+-----+---------+-------+ 

Is it possible to get a count of all widgets that are enabled (enabled = 1) in the same query as a count of all widgets?

For instance, if I have 3 widgets totaled and one is enabled, I’d like to get the results of my query back that look like:

mysql> SELECT ... as enabled_count, ... as total_count ... +---------------+-------------+ | enabled_count | total_count | +---------------+-------------+ |             1 |           3 | +---------------+-------------+ 
  • 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. 2026-05-11T08:34:09+00:00Added an answer on May 11, 2026 at 8:34 am

    If enabled is always 1 or 0, you can do:

    SELECT     COUNT(*) as total_count,    SUM(enabled) as enabled_count  FROM widget 

    If it’s another value, perhaps:

    SELECT    COUNT(*) as total_count,    SUM( CASE WHEN enabled in ('enabled value 1', 'enabled value 2')          THEN 1         ELSE 0         END       ) as enabled_count FROM widget 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple example: Assume I have a customer table that has a
Let's assume we have this very simple table: |class |student| --------------- Math Alice Math
Imagine a simple case like this: class Book has_many :chapters end Let's say in
What is good design in this simple case: Let's say I have a base
I have a very simple case that I think would benefit from using templates
I have a pretty simple case which I started solving using foreach(), but then
What are the rules? OTOH the simple case seems to imply the new type
Let me describe a simple use-case: Running all tests in our project may take
I have a simple unit test case (extensive question here ) on a configuration
I have a table T (structure below) which initially contains all-NULL values in an

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.