Log in

Feb. 25th, 2011 @ 09:13 am MySql noobs
Current Mood: confusedconfused
Hi Guys!

I've got a question for you that's probably pretty easy, but I'm not that familiar with MySQL beyond how to make simple queries.

I'm hoping you can help me out.

I've got two tables: 1 that has when a certain process starts and stops for each company in our database, and one that has all the items that process has to take care of for each company (each item is it's own row).

Right now the query tells me how many companies have been processing their queue since midnight, but I'd like it also to tell me how many items it has left to process for those company.

I tried just adding a count() to the query, but that's not exactly returning the results I want, since I'm not sure how to specify that I want it to pull the count for each individual company.

Can someone point me in the right direction for how to do this all in one nice neat query?

About this Entry
[User Picture Icon]
Date:February 26th, 2011 11:39 pm (UTC)
(Permanent Link)
If you are looking for items for each company separately (ie Costco = 5 items, BJS = 10 items), you can use a group by statement on the item's table. It's been a while since I've used MySql, but it should look something like this:

Select company, count(item) as items_per_co from items join companies on items.co_id = companies.id group by company