2017-03-03 190 views
-1

我的SQL查詢出了問題。我一直在試圖從SQL一些數據,但似乎我在什麼地方失敗了,我無法找到它MySQL查詢語法錯誤:1064 - 您的SQL語法錯誤;

SELECT user_comments.*, 
    users.ID AS user_ID, 
    users.username AS user_username, 
    profiles.userID AS profiles_ID 
    INNER JOIN users ON users.username = user_comments.author 
    INNER JOIN profiles ON profiles.userID = users.ID 
    WHERE user_comments.img_id = 'b75962591b38b117b45d' 

和錯誤是

1064 - 你有一個錯誤在你的SQL語法中;檢查對應於你的MySQL服務器版本的手冊正確的語法使用

附近「INNER JOIN用戶ON users.username = user_comments.author INNER JOIN教授」在5號線

+4

** FROM user_comments **在第一次加入之前丟失 –

回答

1

你忘了FROM user_comments;)

+0

Oh wow ....:|謝謝哈哈哈,有時我只是監督基礎知識...... –

1

你缺少您的查詢中的FROM子句。我假設缺少的表是user_comments

SELECT user_comments.*, 
    users.ID AS user_ID, 
    users.username AS user_username, 
    profiles.userID AS profiles_ID 
    FROM user_comments 
    INNER JOIN users ON users.username = user_comments.author 
    INNER JOIN profiles ON profiles.userID = users.ID 
    WHERE user_comments.img_id = 'b75962591b38b117b45d' 
1

烏爾忘記添加

from user_comments 

試試這個

SELECT user_comments.*, 
    users.ID AS user_ID, 
    users.username AS user_username, 
    profiles.userID AS profiles_ID 
    from user_comments 
    INNER JOIN users ON users.username = user_comments.author 
    INNER JOIN profiles ON profiles.userID = users.ID 
    WHERE user_comments.img_id = 'b75962591b38b117b45d' 
1

添加「FROM 「子句到你的SQL查詢,