I have a fairly large SQL query right now:
SELECT a . * , ap . * , i . * , appstatus . * ,(SELECT SUM(rating) / count( case when rating > 0 then 1 end ) AS total_rating FROM review AS r WHERE r.applyid=a.applyid GROUP BY applyid) AS total_rating, (SELECT count(rating) FROM review AS r WHERE r.applyid=a.applyid GROUP BY applyid) as count
FROM apply AS a, applicant AS ap, interest AS i, application_status AS appstatus, apply_tags as at
WHERE a.applicantid = ap.applicantid
AND a.applicantid = i.applicantid
AND a.application_status_id = appstatus.application_status_id
AND a.archive = 'false'
AND a.jobid =27
I need to modify this so that another table is also checked to see if the a.applyid exists in it or not.
Based on my existing query I want to modify it so it will only be outputting rows that do not have data in the apply_tags table.
I am not sure the best approach to integrate this into my query. Should I be using a join?
I am essentially looking to add an AND statement like this:
AND a.applyid NOT EXIST at.applyid
(at
is the apply_tags table)
I know I am doing this wrong, however that is an example of the kind of thing I am trying to do.