2

ABC という 3 つのテーブルがあり、3 つすべてから情報を取得しようとしています。

A には columnns userid avatar username があり、B には列 postid、dateshared があり、C には列 commenter postid datecommented があります。

クエリを実行しようとしています

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

しかし、次のエラーが発生します。

 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 '

誰かが私が間違っていることを指摘したり、その方法を提案したりできますか?

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 に答える