下面的查询工作正常。它从两个MySQL表“ comment”和“ login”中提取字段。它针对表“登录”中的“用户名”等于变量“ $ profile”的行执行此操作。它还会为表“ comment”中的“ loginid”等于也从“ login”中提取的“ loginid”的行提取字段。

我想从名为“ submission”的第三个表中提取数据,该表具有以下字段:

submissionid loginid title url displayurl datesubmitted


我想从“提交”中的行中提取字段,其中“ loginid”等于已经从其他两个表“ login”和“ comment”中提取的“ loginid”。

我怎样才能做到这一点?

提前致谢,

约翰

查询:

  $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";

最佳答案

SELECT l.username,l.loginid,c.loginid,c.commentid,c.submissionid,c.comment,
c.datecommented,s.submissionid,s.loginid,s.title,s.url,s.displayurl,s.datesubmitted

FROM comment AS c

INNER JOIN login AS l ON c.loginid = l.loginid
INNER JOIN submission AS s ON s.loginid = l.loginid

WHERE l.username = '$profile'

ORDER BY c.datecommented DESC

LIMIT 10

08-19 07:33