Help,
I have a query in MySQL which gets the details of members of a club.
e.g. Select * from members.
however, in the same query I want to return the amount of "functions"
the member has attended.
therefore there is a "functions" table and because functions has a
many-many relationship with members I also have a "functionsl ink"
table.
To get the amount of functions that a particular member has attended
one would write a query like so:
select count(functionl ink_id) as cnt from functionslink where
functionlink.me mber_id=$MEMBER _ID
What I want to do is just have the one query that not only returns all
the member data in its returned row, but also the count of the number
of functions they attended.
At present using PHP code, I make the two calls separately to construct
this data in to a php array, but this involves many more calls to the
DB because for each row returned by the first query, I make another
call to the DB and something tells me this is a slow bad way of doing
things.
I am sure this is a simple common query but I cannot work it out.
Thanks in advance.
I have a query in MySQL which gets the details of members of a club.
e.g. Select * from members.
however, in the same query I want to return the amount of "functions"
the member has attended.
therefore there is a "functions" table and because functions has a
many-many relationship with members I also have a "functionsl ink"
table.
To get the amount of functions that a particular member has attended
one would write a query like so:
select count(functionl ink_id) as cnt from functionslink where
functionlink.me mber_id=$MEMBER _ID
What I want to do is just have the one query that not only returns all
the member data in its returned row, but also the count of the number
of functions they attended.
At present using PHP code, I make the two calls separately to construct
this data in to a php array, but this involves many more calls to the
DB because for each row returned by the first query, I make another
call to the DB and something tells me this is a slow bad way of doing
things.
I am sure this is a simple common query but I cannot work it out.
Thanks in advance.
Comment