topacoBoy topacoBoy - 3 months ago 7
MySQL Question

How can i get the total of a column in mysql?

Alright, I am kind of new to SQL and I have no idea on how I am going to do this. I have tried to google but maybe I'm not sure if I am searching for the right question. So here it is. I have 2 tables in my database. One is called

events
and another one is called
eventtypes
.

My
eventtype
table looks like this..

-------------------
eventID | eventName|
1 | eveA |
2 | eveB |
3 | eveC |
___________________


and my
events
table, looks like this

--------------------------
eventCat |UserRegistered |
1 | John |
2 | Mac |
3 | Assz |
2 | Ez |
3 | Pz |
_________________________


(I hope you understand my table.....)

events.eventCat=eventtype.eventID


Now, what I am trying to do is to, calculate the numbers of participants for event 1, 2 and 3 in
events
table and later display the number of users who will be attending appropriately by using the
eventtype
table using php.

Can somebody help me out with this ? Thanks a bunch !

Answer

You can apply join and group by to acheive this -

SELECT count(UserRegistered),eventName from events join eventtype on
  events.eventCat=eventtype.eventID
     GROUP BY eventCat

Hope this will help you.