Я получил следующую ошибку ниже и задавался вопросом, как я могу ее исправить?
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 '.user_id WHERE
users.active IS NULL AND users.deletion = 0) WHERE users.active' at line 4
И вот мой код MySQL (строки разрывы вставлены так, что строка 4 в сообщении об ошибке соответствует 8).
SELECT users.user_id, articles_comments.article_id, articles_comments.comment,
articles_comments.comment_id
FROM users_articles
INNER JOIN articles_comments
ON users_articles.id = articles_comments.article_id
INNER JOIN (SELECT *
FROM users INNER JOIN users_articles.user_id = users.user_id
WHERE users.active IS NULL AND users.deletion = 0)
WHERE users.active IS NULL
AND users.deletion = 0
ORDER BY articles_comments.date_created DESC
LIMIT 50
SELECT users.user_id, articles_comments.article_id, articles_comments.comment, articles_comments.comment_id
FROM users_articles
INNER JOIN articles_comments ON users_articles.id = articles_comments.article_id
INNER JOIN (SELECT * FROM users INNER JOIN users_articles ON users_articles.user_id = users.user_id WHERE users.active IS NULL AND users.deletion = 0) x
WHERE x.active IS NULL
AND x.deletion = 0
ORDER BY articles_comments.date_created DESC
LIMIT 50
Пояснение:
INNER JOIN users_articles.user_id = users.user_id
Это проблема. Вы забыли указать объединенную таблицу и ключевое слово ON
UPD: попробуйте этот запрос. Он должен делать то же самое, но гораздо более удобочитаемое
SELECT *
FROM users_articles a
INNER JOIN articles_comments c ON c.article_id = a.id
INNER JOIN users u ON u.user_id = a.user_id
AND u.active IS NULL
AND u.deletion = 0
ORDER BY c.date_created DESC
LIMIT 50
отсутствует "ON" по адресу:
INNER JOIN (SELECT * FROM users INNER JOIN users_articles ON users_articles.user_id = users.user_id WHERE users.active IS NULL AND users.deletion = 0)
вы можете больше понять с помощью this