Join Query Help

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-11T15:32:27Z Indexed on 2010/05/11 16:24 UTC
Read the original article Hit count: 328

Filed under:
|
|

Hello,

The query below works well. It pulls data from two MySQL tables, "submission" and "login." I would like to also pull data from a third table called "comment" in the same database.

The table "comment" has the following fields:

commentid, loginid, submissionid, comment, datecommented

Two of the fields in the table "login" are called "loginid" and "username."

In the query below, I would like to count all "commentid" in "comment" where "loginid" equals the "loginid" in "login" where "username" equals "$profile."

How can I do this?

Thanks in advance,

John

$sqlStr1 = "SELECT l.username, l.loginid, s.loginid, s.submissionid, s.title, s.url, s.datesubmitted, s.displayurl, l.created, count(s.submissionid) countSubmissions
               FROM submission AS s
         INNER JOIN login AS l
                 ON s.loginid = l.loginid
              WHERE l.username = '$profile'";

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql