1
select a.*
from article as a
where a.status_id = 2 and count(select h.id from article_history as h where h.article_id = a.id and h.event_id = 5) = 0

[Err] 1064 - 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 'select h.id from article_history as h where h.article_id = a.id and h.event_id =' at line 3

9
  • Скорее всего ругается на имя поля id. Попробуйте их обернуть так: h.id 20 апр 2018 в 10:55
  • @УстьянцевБорис сто лет уже так работаю. Никогда не ругалось. Не причем тут названия...
    – Developer
    20 апр 2018 в 10:56
  • Хм. Разметка режет бектики. Это обратные апострофы (на клавише с ё). 20 апр 2018 в 10:57
  • 1
    А если заменить count(select h.id from article_history as h where h.article_id = a.id and h.event_id = 5) на (select count(h.id) from article_history as h where h.article_id = a.id and h.event_id = 5)? Хотя поидее смысл тот же
    – chubatiy
    20 апр 2018 в 11:02
  • 2
    @DarkByte насколько я знаю, COUNT нельзя использовать в WHERE: только в SELECT и в HAVING.
    – Regent
    20 апр 2018 в 11:05

1 ответ 1

4

Замените

count(select h.id from article_history as h where h.article_id = a.id and h.event_id = 5) 

на

(select count(h.id) from article_history as h where h.article_id = a.id and h.event_id = 5)

Как было озвученно в комментариях к вопросу участником Regent:

COUNT нельзя использовать в WHERE: только в SELECT и в HAVING

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.