How to write optimal SQL query with a calculated field?

Good day, please help to write an optimal SQL query
there are three tables:
  1. Events
  2. Participants
  3. Users



Accordingly, the user registering for the event to become a party. Participants table implements the many-to-many relation between Events and Users.

Noino, given the ID of the user to make a selection of all events and add a calculated field of type boolen - is this user a participant in the event.

I want to make it a single query, and as fast
April 4th 20 at 13:27
2 answers
April 4th 20 at 13:29
Solution
The issues of optimization of the queries is not meaningful without specifying the underlying DBMS.

select ..., p.event_id is not null from events as e left join participations p on p as.user_id = ? and e.id = p.event_id

either
select ..., exists(select null from participations as p on p.user_id = ? and e.id = p.event_id) from events as e
Thank you - Aimee.Goyette commented on April 4th 20 at 13:32
April 4th 20 at 13:31
Noino
No. It is sufficient to determine the user ID in the "Members", the subquery, for example.

Find more questions by tags SQLOptimization of SQL-queries