Using Postgres I've written the following query:
SELECT
*,
CASE
WHEN
(SELECT count(*) FROM applications WHERE applications.user_id = 774 AND applications.job_id = jobs.id) > 0
THEN 1
ELSE 0
END
AS has_applied
FROM jobs
It selects all of the jobs from my database and runs a check to see if the currently logged in user (with an ID of 774 in this case) has applied to the job.
I see only one query run in my database GUI, but doesn't this have to run the nested query for each row from the jobs
table?
Is there a better way to write this? Or does this seem like something that should be done by comparing the datasets from two separate queries?