Adding a Third Table to a Two-Table Join Query
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-19T20:03:27Z
Indexed on
2010/05/19
20:10 UTC
Read the original article
Hit count: 229
Hello,
The query below works just fine. It pulls fields from two MySQL tables, "comment" and "login". It does this for rows where "username" in the table "login" equals the variable "$profile." It also pulls fields for rows where "loginid" in the table "comment" equals the "loginid" that is also being pulled from "login."
I would like to pull data from a third table called "submission," which has the following fields:
submissionid loginid title url displayurl datesubmitted
I would like to pull fields from rows in "submission" where "loginid" equals the "loginid" that is already being pulled from the other two tables, "login" and "comment."
How can I do this?
Thanks in advance,
John
Query:
$sqlStrc = "SELECT l.username, l.loginid, c.loginid, c.commentid, c.submissionid, c.comment, c.datecommented
FROM comment AS c
INNER JOIN login AS l
ON c.loginid = l.loginid
WHERE l.username = '$profile'
ORDER BY c.datecommented DESC
LIMIT 10";
© Stack Overflow or respective owner