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 Answer