Thread: Resolved count rows inside array
View Single Post
Old 12-03-2012, 05:59 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Nope. First of all, when you do COUNT(state) then, unless some of the records in your text table have *NULL* state values, then you will get *exactly* the same answer as if you did
Code:
SELECT COUNT(*) AS num FROM test WHERE country = 'us'
In other words the TOTAL COUNT OF ALL records that match on country = 'us'. ONE SINGLE NUMBER. Period.

In short, COUNT(state) does not *AT ALL* mean what you think it means.

I *think* that what you are after is this:
Code:
SELECT state, COUNT(*) AS num FROM test 
WHERE COUNTRY='us'
GROUP BY state
ORDER BY state
And that will give you records such as
Code:
Alabama   37
Alaska     5
.. etc. ...
But of course now you won't want to use implode, more than likely.

I'm not sure why you ever wanted to use implode in the first place. What use is it?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
sonny (12-03-2012)