Reputation: 7053
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
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
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