I have two tables resource (id, name, ...) and user_favorites(user_id, resource_id) which has foreign key resource_id from the resource table.
I have a situation where I need to check if resource table has any records to user_favorites table for a particular user_id in user_favorites table, and put a flag true or false accordingly.
This is the last query I could come up with
SELECT distinct resources.*,
(CASE WHEN user_favorites.user_id='1' then 'TRUE' ELSE 'FALSE' END) as favorite,
user_favorites.user_id
FROM resources LEFT JOIN
user_favorites
ON resources.id = user_favorites.resource_id
However, what I want to be able to keep the resources. With the current query, it records false when there are records for other user ids also.
What is the best way to approach this problem?