There is a MySQL query that returns all comments.
But I need to return only those where the field comments.is_active=1 . It is impossible to correct, already tortured, constantly:

You have an error in your SQL syntax ...

Where to add WHERE c.is_active=1 ?

 SELECT c.id_comment, c.id_parent, u.login, n.title_news, cat.category_name, c.`comment`, c.date_time, c.is_active FROM comments c LEFT JOIN users u ON u.id = c.id_user LEFT JOIN news n ON n.id_news = c.id_news LEFT JOIN category cat ON cat.id_category = n.id_category ORDER BY c.date_time DESC LIMIT {$start},{$limit}; 

    1 answer 1

    A standard select query ( SELECT ) in SQL in most cases consists of or can consist of the following operators:

     SELECT ΠΊΠΎΠ»ΠΎΠ½ΠΊΠΈ FROM Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ JOIN Ρ‚Π°Π±Π»ΠΈΡ†Π° WHERE условия GROUP BY ΠΊΠΎΠ»ΠΎΠ½ΠΊΠΈ HAVING условиС ORDER BY ΠΊΠΎΠ»ΠΎΠ½ΠΊΠΈ 

    A more detailed SELECT specification for MySQL can be obtained here .

    Reordering is not allowed . Therefore, based on the above example, the WHERE condition you should go after JOINs:

     SELECT c.id_comment, c.id_parent, u.login, n.title_news, cat.category_name, c.`comment`, c.date_time, c.is_active FROM comments c LEFT JOIN users u ON u.id = c.id_user LEFT JOIN news n ON n.id_news = c.id_news LEFT JOIN category cat ON cat.id_category = n.id_category WHERE c.is_active=1 ORDER BY c.date_time DESC LIMIT {$start},{$limit};