NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL count( * ) syntax question

Christopher R. Merlo cmerlo at ncc.edu
Mon Feb 9 19:17:16 EST 2004


On 2004-02-09 19:09 -0500, Mitch Pirtle <mitchy at spacemonkeylabs.com> wrote:

> >Basically, I want to select every student, and the amount of times
> >he/she was absent (including never).  But I only get the students who
> >were absent at least once.  I can't think of another way to get that,
> >other than what feels like it would be a severe kludge.
> 
> Would that kludge include the use of mysql_num_rows?  You could just add 
> that to your processing, or perhaps play about with SUM() and GROUP BY...

Yeah, essentially a second query within the foreach of the first
query.  I suppose it'll work, but then I won't be able to sort the
first query by amount of absences.  If that's the best solution, then
so be it.

I've been reading ppl's advice on devshed and dbforums about using a
left join instead of just "from login, attendace".  I think I'm
following their advice, and it's not working.  This query:

mysql> select l.first, l.last, count( a.attended )
    -> from attendance as a left join login as l
    -> on ( l.id = a.student )
    -> where a.attended = 2 and l.section = 1
    -> group by l.id
    -> ;

still only gives me the rows where the count > 0.  I've also switched
the order of the tables in the from line without success.

-- 
  cmerlo at ncc.edu             http://turing.matcmp.ncc.edu/~cmerlo

In theory, there is no difference between theory and practice.  In
practice, there is.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040209/635ee2f1/attachment.sig>


More information about the talk mailing list