How to build a query so that I can find all events along with an extra bool column “attending” which is a join on attendees table?

You could use exists:

select e.*, 
        select 1 
        from events_attendees ea 
        where ea.pin_id = and ea.user_id = 656
    ) attending
from events e

An alternative is a left join:

select e.*, (ea.pin_id is not null) attending
from events e
left join events_attendees ea on ea.pin_id = and ea.user_id = 656

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top