I have tables queue and requests. queue's reqID is a foreign key to requests' reqID. both tables have vanID
I am trying to get all the stuff in queue, as well as all the information for each request that queue references. This is my query.
$sql = mysql_query("SELECT queue.*, requests.*
FROM queue
WHERE queue.vanID = '$vanID'
LEFT JOIN requests ON queue.reqID = requests.reqID
开发者_C百科 ORDER BY rank ASC") or die(mysql_error());
This the error I'm getting.
1064: 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 'LEFT JOIN requests ON queue.reqID = requests.reqID ORDER by rank ASC' at line 1
I can't seem to figure it out, any help?
$sql = mysql_query("SELECT queue.*, requests.* FROM queue LEFT JOIN requests ON queue.reqID = requests.reqID WHERE queue.vanID = '$vanID' ORDER by rank ASC") or die(mysql_error());
You were close. The WHERE
clause should go after the LEFT JOIN
.
The joins are part of the from
section of a query, and, as such, must come before the where
section :
SELECT queue.*, requests.*
FROM queue
LEFT JOIN requests ON queue.reqID = requests.reqID
WHERE queue.vanID = '$vanID'
ORDER by rank ASC
精彩评论