Answer the question
In order to leave comments, you need to log in
What is the best way to get user likes along with messages?
It is necessary to get information about whether the user who views the messages likes it. What is the best way to do this?
At the moment, a request has been written to receive posts and the number of likes.
SELECT `p`.`id`, `p`.`userId`, `p`.`message`, COUNT(`pl`.`postId`) as cnt_likes
FROM `posts` AS `p`
LEFT JOIN `post_likes` AS `pl` ON `pl`.`postId` = `p`.`id`
WHERE `p`.`userId` = :userId
GROUP BY `p`.`id`
ORDER BY `p`.`id` DESC
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question