I’m trying to create a query that will return all the jobs published by a specific company, and a count of the total people who applied to this job. the first part works fine – I get all the jobs and everything I need:
$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 ".
"ja.user_id = '".$_SESSION['user_id']."' AND ".
"j.job_id = ja.job_id WHERE j.job_company='$company_id'";
The thing is, that I want to add each result row the number of applicants for the job from the jobApplications table… I tried to add a COUNT column to the query, which works great by itself:
SELECT COUNT(*) FROM jobApplications ja WHERE ja.job_id=j.job_id
when added to the first big query, I didn’t manage to make this work even on the syntax level, so i’m not sure if it works at all…
I tried to add the last query to the select area of the main query, but I always get a syntax error right after the ‘ja.job_id=j.job_id’ in the end of the count query…
Is this even possible ?
I hope the question is clear, I know there are many tables included here…
Thanks for the time and help!
i dont know your PK of jobApplications, but this might work.