Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Brain loss causes bad query 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR

Hello,

Doing less and less mysql until recently, I just had the bad surprise to discover that there are some basic stuff that have escaped from my brain during all this time ;(

For exemple, I can't remember how to do this with a single query :

I have one table such as

category | objects
-------------------
A | 1
B | 2
A | 3
B | 4
A | 5
B | 6
A | 7
-------------------

I need to return the following sentence :
Category A has 4 items and category B has 3 items and ...etc ...

Note that categories aren't fixed.

Thanks so much :(

 
[tt]select category
, count(*) as objects
from onetable
group
by category[/tt[

rudy
SQL Consulting
 

Oh my god ... that's wonderful ! Thanks !

I was mislead by thinking that COUNT would retrieve the rows within the scope of the GROUP BY function.

Many many thanks!
Have a nice day :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top