select product_id
from products_comments
group by product_id
having max(case when comment_id in (1,2) then 1 else 9 end) = 1
select product_id
from products_comments
group by product_id
having max(comment_id) = 1
SELECT
u.*,
ui.`image_name`,
(SELECT COUNT(il.`id`) FROM images_likes AS il WHERE `il`.image_id = `ui`.id) AS count_likes,
FROM users AS u
LEFT JOIN (select row_number() over(partition by user_id order by id) rn, user_id , id, image_name
from users_images) AS ui ON ui.user_id = u.id and ui.rn <= 5
WHERE u.flag > 0