|
Posted by Bonge Boo! on 09/09/05 17:45
On 9/9/05 13:29, in article dfrv2r$90m$1@news.onet.pl, "Hilarion"
<hilarion@SPAM.op.SMIECI.pl> wrote:
>> Any suggestions? My MYSQL query skills are limited, but I'm trying to expand
>> them. This seemed a good place to start.
>
>
> To get count of people for each event do something like this:
>
> SELECT event_table.event_id, event_table.event_name, count(
> people_table.person_id ) AS cnt
> FROM event_table LEFT JOIN people_table ON event_table.event_id =
> people_table.event_id
> GROUP BY event_table.event_id, event_table.event_name
> ORDER BY event_table.event_name, event_table.event_id
>
> To get a count of people for one event you could add WHERE clause to the query
> above (after FROM clause and before GROUP BY clause) or use one query to
> get the event data and another to get the count:
>
> SELECT count(*) AS cnt
> FROM people_table
> WHERE event_id = $event_id
>
>
> If you want to use the first query and get more data from the event_table,
> then
> don't forget to put the additional column names in GROUP BY clause (it's
> probably
> not needed in MySQL, but will make the query work also in other SQL engines
> and should be less dependant on the table structure).
<Gulp> Lots to digest and learn </Gulp>
I didn't realise I could count the hits from a column like that. Very
useful. I'll now go play with it and see if I can extend it to further
tables.
Thank you.
Navigation:
[Reply to this message]
|