views:

174

answers:

1
SELECT Question.userid, user.uid
FROM `question`
WHERE NOT `userid`=2
LIMIT 0, 60
INNER JOIN `user`
ON `question`.userid=`user`.uid
ORDER BY `question`.userid

returns 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 'INNER JOIN User ON question.userid=user.uid ORDER BY question.userid' at line 5

Can't for the life of me figure out what I'm doing wrong here.

+1  A: 

Your query doesn't look valid. You may want to try the following:

SELECT      `question`.userid, `user`.uid
FROM        `question`
INNER JOIN  `user` ON `question`.userid = `user`.uid
WHERE       `userid` <> 2
ORDER BY    `question`.userid
LIMIT       0, 60
Daniel Vassallo
Nailed it on the head! You sir are my savior for the day!
David van Dugteren
Out of interest, do you know what was wrong with line 5? i.e. INNER JOIN ON
David van Dugteren
@David: Your only syntax error was `WHERE NOT userid=2` where you had to use `WHERE userid <> 2`. Otherwise it was simply the order of the clauses that was incorrect. `LIMIT` must always be the last. The `WHERE` clause needs to follow the `FROM` and all the `JOIN`s, etc. The `INNER JOIN` syntax was fine. It was just at the wrong place, since it had a `WHERE` before it.
Daniel Vassallo
Ah thanks, though the 'WHERE NOT' clause actually was valid, I was using it before adding the INNER JOIN part, if that makes sense.
David van Dugteren
@David: You're right, it is valid! Wasn't thinking :) ... It was just the ordering then.
Daniel Vassallo