开发者

MySQL: Syntaxerror when using Join?

Can you find anything wrong with this query?

        SELECT * FROM requests 
        WHERE id = '".$id."' 
        LEFT JOIN request_data ON (requests.id = request_data.request_id) 
        GROUP BY requests.id 

Been workingon it for a while but can't seem to get it right!

The database looks like this:

 -requests
   -id
   -another column
   -and a third one

 -request_data
   -request_id
   -key
   -value

EDIT: Oh right, and the error:

You have an error in your SQL syntax; check the manual that correspo开发者_JS百科nds to your MySQL server version for the right syntax to use near 'LEFT JOIN request_data ON (requests.id = request_data.request_id) GROUP BY ' at line 3

Any ideas?


The WHERE is in the wrong place.

    SELECT *
    FROM requests 
    LEFT JOIN request_data ON (requests.id = request_data.request_id) 
    WHERE id = '".$id."' 

You probably don't need a GROUP BY either as the WHERE ensures there will only be one id returned unless in some way you are relying on the hidden columns functionality (which you shouldn't as the results are undefined).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜