Adding a third table to a Join

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-22T18:32:50Z Indexed on 2010/03/22 18:41 UTC
Read the original article Hit count: 449

Filed under:
|

Hello,

This query works fine:

$sqlStr = "SELECT s.loginid, s.title, s.url, s.displayurl, l.username
             FROM submission AS s,
                  login AS l
            WHERE s.loginid = l.loginid
         ORDER BY s.datesubmitted DESC
            LIMIT 10";

Would this work if I wanted to join a third MySQL table (called "comment") to it?

$sqlStr = "SELECT s.loginid, s.submissionid s.title, s.url, s.displayurl, l.username, count(c.comment) countComments
             FROM submission AS s,
                  login AS l, 
                  comment AS c,
            WHERE s.loginid = l.loginid
              AND s.submissionid = c.submissionid
         ORDER BY s.datesubmitted DESC
            LIMIT 10";

Thanks in advance,

John

© Stack Overflow or respective owner

Related posts about mysql

Related posts about php