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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:55:51+00:00 2026-06-11T19:55:51+00:00

I have a table structure like this: CREATE TABLE `test` ( `a` tinyint(3) unsigned

  • 0

I have a table structure like this:

CREATE TABLE `test` (
  `a` tinyint(3) unsigned DEFAULT 0,
  `b` tinyint(3) unsigned DEFAULT 0,
   `c` tinyint(3) unsigned DEFAULT 0,
  `d` tinyint(3) unsigned DEFAULT 0,
  `e` tinyint(3) unsigned DEFAULT 0
  );

This has about 30 columns with some columns that have values from 0-200 (a,b) and some only have 5 values (0,1,2,3,4) (column c-d). There are aprox. 120k rows in the table.

To show the number of items per row I use a query for each column:

select a, count(*) FROM test group by a;
select b, count(*) FROM test group by b;
select c, count(*) FROM test group by c;
select d, count(*) FROM test group by d;
select e, count(*) FROM test group by e;

The problem with this is that it will fire 30 queries (one per column) and basically goes over the same set of data each time.

Is there a better way to do this?

I have tried with GROUP BY WITH ROLLUP but this results in a massive resultset which is slower to process than each individual query.

You can view a selection of the data on SQLfiddle: http://sqlfiddle.com/#!2/a9fd8/1

  • 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-11T19:55:52+00:00Added an answer on June 11, 2026 at 7:55 pm

    Maybe something like this will work faster.

    select qq, q, count(*) from
    (
    select 'a' qq, a q FROM test
    union all select 'b' qq, b q FROM test
    union all select 'c' qq, c q FROM test
    union all select 'd' qq, d q FROM test
    union all select 'e' qq, e q FROM test
    ) t
    group by qq, q;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I have some nicely-structured data that looks like this: CREATE TABLE SourceBodyPartColors ( person_ID
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have a table for a Statistical project. Structure is like this: CREATE TABLE
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
So I have a database that has a structure something like this: [user_table] user_id,
I have two tables, A and B. The structure looks like this: CREATE TABLE
I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_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.