2

I have three tables A B C and i'm trying to retrieve information from all three.

A has the columnns userid avatar username and B has the column postid, dateshared and C has the column commenter postid datecommented.

I'm trying to run the query

Select  C.comment, C.commenter,  C.datecommented, B.postid, B.dateshared A.username A.avatar from B Left Join C  Left join A on C.postid = B.postid AND A.userid = C.commenter where B.postid IN ('1','2','3') order by  C.dateshared desc

but it gives the following error:

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where B.postid IN ('1', '2', '3') order by C.dateshared '

Can anyone point out what I'm doing wrong or suggest how to go about it?

4

2 回答 2

2

每个都LEFT JOIN需要自己的ON条件:

SELECT  C.comment, C.commenter, C.datecommented, B.postid, B.dateshared, A.username A.avatar
FROM    B
LEFT JOIN
        C
ON      C.postid = B.postid
LEFT JOIN
        A
ON      A.userid = C.commenter
WHERE   B.postid IN ('1','2','3')
ORDER BY
        C.dateshared desc
于 2013-04-17T23:21:08.837 回答
0

这应该对您有用,您的查询有一些语法错误:

Select  C.comment,C.commenter,C.datecommented,B.postid,B.dateshared,A.username,A.avatar
from B
Left Join C on C.postid = B.postid
Left join A on A.userid = C.commenter
where B.postid IN ('1','2','3')
order by  C.dateshared desc
于 2013-04-19T06:00:37.740 回答