Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

mysql syntax error on inner join statement

I want to get the 5 last rows from two tables.

Here is the mysql statement I execute:

"SELECT title, thread_id
FROM threads AS t1
JOIN ON comments AS c1 ON t1.user_id = c1.user_id
 WHERE t1.user_id=".$userID
." OR c1.user_id=".$userID.
" ORDER BY thread_id DESC
LIMIT 0,5"

Here is the mistake:

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 'ON comments AS c1 ON t1.user_id = c1.user_id WHERE t1.user_id=1 OR c1.' at line 3

What am I doing wrong?!?

Upvotes: 0

Views: 340

Answers (3)

Thein Hla Maw
Thein Hla Maw

Reputation: 683

Remove the extra ON in 3rd line. It will works.

"SELECT title, thread_id
FROM threads AS t1
JOIN comments AS c1 ON t1.user_id = c1.user_id
 WHERE t1.user_id=".$userID
." OR c1.user_id=".$userID.
" ORDER BY thread_id DESC
LIMIT 0,5"

Upvotes: 0

Kokers
Kokers

Reputation: 1828

There isnt anything like JOIN ON should be just JOIN or INNER JOIN, LEFT JOIN. something like this:

"SELECT title, thread_id
FROM threads AS t1
JOIN comments AS c1 ON t1.user_id = c1.user_id
 WHERE t1.user_id=".$userID
." OR c1.user_id=".$userID.
" ORDER BY thread_id DESC
LIMIT 0,5"

Upvotes: 2

deceze
deceze

Reputation: 522081

You have a superfluous ON before comments.

Upvotes: 2

Related Questions