[英]mysql syntax error on inner join statement
我想從兩個表中獲取最后5行。
這是我執行的mysql語句:
"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"
這是錯誤:
您的SQL語法有誤; 請檢查與您的MySQL服務器版本相對應的手冊,以獲取正確的語法,以在“在ON注釋AS c1上t1.user_id = c1.user_id WHERE t1.user_id = 1 OR c1附近使用注釋”附近使用。 在第3行
我究竟做錯了什么?!?
你有多余的ON
之前comments
。
沒有類似JOIN ON
東西應該是JOIN
或INNER JOIN
, LEFT JOIN
。 像這樣的東西:
"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"
刪除第3行中多余的ON。 它將起作用。
"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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.