I’m having problems adding a conditional field to my query.
The query returns the jobs that are published on my website (many joines, nothing very speical). The thing is I need to add another field in order to know if the current user already applied for this job (in order to remove the APPLY button)…
I have a jobApplication table, which has the user_id and job_id tables. I thought about using another join but that can’t work. I tried to create it with an IF and SELECT but didn’t quite managed to make it work :/…
this is my query:
SELECT *, j.job_id as jid, c.name as city_name
FROM jobs j
JOIN areas a ON a.area_id = j.job_area
JOIN positions p ON p.position_id = j.job_position
JOIN fields f ON f.id = j.job_field
JOIN cities c ON j.job_city = c.id
JOIN jobTypes jt ON j.job_type = jt.job_id
JOIN companies comp ON j.job_company = comp.company_id
LEFT JOIN jobApplications ja ON <missing>
WHERE j.job_field = '$field' AND j.job_position = '$position'
AND j.job_area = '$area'
ORDER BY j.creationDate DESC"
any attempt I made to add a condition select broke the query, any chance someone can give me a better direction?
Thanks!!
It’s hard to say for sure without knowing more about your schema, but you are on the right track with the left join. You will need to left join onto the applicants table using the applicant Id for the current user and to the job ID from the jobs table.