Jump to content

Counting in mysql


Linuus

Recommended Posts

Hi!

 

I'm using Joomla and I need to create a query that counts all rows (articles) in my table that have the same "parent_id" (category). I can do it like this:

 

SELECT COUNT(*) FROM table WHERE parent_id = $my_id

 

and then loop that for every parent_id. There might be many parent_ids so I wonder if I somehow can count everything in one query and then get the data from an array with a loop.

Like use the GROUP by parent_id COUNT(*) as c ....

 

I hope someone understands what I mean. If not, scream and I will try to explain better :)

 

Mysql version: 5.0.67

 

Best regards

Linus

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.