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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:31:26+00:00 2026-06-16T09:31:26+00:00

I am not certain how to do this select. Here is my table structure.

  • 0

I am not certain how to do this select. Here is my table structure.

CREATE TABLE `my_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `step` int(2) NOT NULL DEFAULT '0',
  `title` varchar(200) NOT NULL,
  `description` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;

The step column will contain an integer between 0 and 7. I am attempting to count how many records I have in my table for the range of steps 1 through 6. I need the entire range (1 – 6) including where COUNT equals zero. I would like it to return in order — something like this.

+----------+----------+
|   step   |     n    |
+----------+----------+
|   Step 1 |     100  |
+----------+----------+
|   Step 2 |     150  |
+----------+----------+
|   Step 3 |     135  |
+----------+----------+

I was hoping I would not need to define a procedure for this. Is there a simple way of getting what I need?

  • 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-16T09:31:28+00:00Added an answer on June 16, 2026 at 9:31 am
    SELECT
        s.step
      , COALESCE(t.n, 0) AS n
    FROM
            ( SELECT 1 AS step UNION ALL
              SELECT 2 UNION ALL
              SELECT 3 UNION ALL
              SELECT 4 UNION ALL
              SELECT 5 UNION ALL
              SELECT 6 
            ) AS s
        LEFT JOIN
            ( SELECT step 
                   , COUNT(*) AS n 
              FROM my_table 
              GROUP BY step 
            ) AS t
          ON t.step = s.step
    ORDER BY
        s.step ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not certain about this and searching a bit hasn't turned up anything
I'm not certain how to explain this with the correct terms so maybe an
I apologize if this has already been asked - I'm not certain of the
I know this sort of code is not best practice, but nevertheless in certain
I'm having hard time trying to set certain cell's value in table. Here is
I have a MySQL table like this one: day int(11) hour int(11) amount int(11)
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+
I'm looking at code, and I'm not certain of its functionality. I looked at
I've got a C# control wrapped around the DirectShow libraries. Though I'm not certain
I've found that the Like Box app for Facebook will not recognise certain pages

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.