PDA

View Full Version : help with query to select counts


Jakeman
05-02-2004, 05:28 AM
I want to select the number of records for each idnumber that exists. In the below example, there are three 2's, four 3's, and three 4's. I want to capture this information in a single query if possible.

I know how to capture a record count for a single idnumber, but I'm not sure how to do capture counts for multiple idnumbers in one query.

An example of the table:


____________________
| idnumber | title |
|-------------------
| 2 | ..... |
| 2 | ..... |
| 2 | ..... |
| 3 | ..... |
| 3 | ..... |
| 3 | ..... |
| 3 | ..... |
| 4 | ..... |
| 4 | ..... |
| 4 | ..... |


Any help is appreciated.

Xenon
05-02-2004, 10:43 AM
you need grouping:

SELECT COUNT(*), idnumber
FROM table
GROUP BY idnumber

sabret00the
05-02-2004, 10:07 PM
i think he wants to capture the count of 2, then the count of 3's then the count of 4's

if that's the case, i'm not sure how to do it i'm afraid, it's what i'm reading up on now, but i'm pretty certain it's via a "while"

Jakeman
05-03-2004, 03:08 AM
you need grouping:

SELECT COUNT(*), idnumber
FROM table
GROUP BY idnumber

that worked. thx

Boofo
05-03-2004, 04:50 AM
i think he wants to capture the count of 2, then the count of 3's then the count of 4's

if that's the case, i'm not sure how to do it i'm afraid, it's what i'm reading up on now, but i'm pretty certain it's via a "while"

The code Stefan posted will do that. ;)

Xenon
05-03-2004, 04:35 PM
You're welcome Jake :)