下面的查询工作得很好。它从两个MySQL表中提取字段,“注释”和“登录”。它对表格“login”中的“username”等于变量“$ profile”的行执行此操作。它还为行中的字段提取字段,其中“comment”表中的“loginid”等于“loginid”,该“loginid”也是从“login”中提取的。
我想从名为“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";
答案 0 :(得分:3)
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