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; If you’re not sure, you’ll find out where you’re looking for a html from the article_history where h.article_id = a.id and h.event_id = 'at line 3

  • Most likely swears on the name of the id field. Try wrapping them like this: h. id - Boris Ustyantsev
  • @ UstyantsevBoris have been working this way for a hundred years. Never swore. Nothing to do with the name ... - PECHAPTER
  • Hm Markup cuts bektiki. These are reverse apostrophes (on the c key). - Ustyantsev Boris
  • one
    And if you replace count(select h.id from article_history as h where h.article_id = a.id and h.event_id = 5) with (select count(h.id) from article_history as h where h.article_id = a.id and h.event_id = 5) ? Although the idea is the same - Chubatiy
  • 2
    @DarkByte as far as I know, COUNT cannot be used in WHERE : only in SELECT and in HAVING . - Regent

1 answer 1

Replace

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

on

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

As it was voiced in the comments to the question by a Regent member:

COUNT cannot be used in WHERE: only in SELECT and in HAVING