I have to select list of users and for each of them I have to return info that he is followed or not (by current/requesting user). For now I query like this:
SELECT
"User"."name",
EXISTS(
SELECT * FROM "Followings" f WHERE f."FollowedId" = "User"."id" AND f."FollowerId" = 123
)::boolean AS "isFollowed"
FROM "Users" AS "User"
ORDER BY "User"."createdAt"
LIMIT 15
Note: 123 is id of user that retrieves list of user.
Is id good idea to make such nested SELECT? What is performance of such query?
My second idea is just to make "Users" LEFT JOIN "Followings"
- if following is joined then user is followed. Which of the approaches will be better?