The following query is giving me this error:
Error Code: 1054. Unknown column 'jobs.id' in 'on clause'
SELECT clinics.id as cid, clinics.name, clinics.address AS clinicAddress,
clinics.post_code as clinicZip, clinics.city AS clinicCity, clinics.region,
countries.full_name AS country,
jobs.name AS jobName, jobs.created_at AS jobCreatedAt, jobs.from AS jobStarts,
jobs.description AS jobDescription, jobs.rates, jobs.max_applicants, jobs.created_at,
locum_types.name AS locumName,
job_statuses.name AS statusName,
CONCAT(users.first_name, ' ', users.last_name) AS userName, users.title AS userTitle,
roles.name AS roleName
FROM clinics
JOIN countries ON countries.id = clinics.country_id
JOIN jobs ON clinics.id = jobs.clinics_id
JOIN users ON users.id = jobs.users_id
JOIN roles ON roles.id = users.roles_id
JOIN locum_types ON locum_types.id = jobs.locum_types_id
JOIN job_statuses ON job_statuses.id = jobs.statuses_id
WHERE (LOWER(`clinics`.`city`) like '%abbey%'
OR LOWER(`clinics`.`post_code`) like '%abbey%'
OR LOWER(`clinics`.`region`) like '%abbey%')
AND jobs.to >= '2020-01-31 07:53:48'
AND applicants IN (SELECT COUNT(user_jobs_application.id) as applicants
FROM user_jobs_application
JOIN user_jobs_application as jobApplication ON user_jobs_application.jobs_id = jobs.id
HAVING applicants < jobs.max_applicants)
LIMIT 20 OFFSET 0
I am trying to count all jobs in the user_jobs_application table and check if the count is lesser than the max_applicants in jobs table.
The structure of the jobs table is following:
id
max_applicants
created_at
The user_jobs_application table (this is pivot table):
id
users_id
jobs_id
Basically I need to count all applications for the job and check if it within limits (max_applicants). Any idea what am I doing wrong here?