Select from table A where in table B for one condition, but not in table B for another condition
Posted on 2011-02-24
I've got a table that holds leads (id, firstname, surname etc)
Then I have another table which keeps a record of lead activity, i.e. when it's been viewed and assigned etc (id, person_id, lead_id, description). In this case, the description will hold the type of activity (viewed, assigned, deleted).
What I need to do is get a list of leads where they've been assigned, but not viewed. This would mean essential mean...
SELECT * FROM leads,lead_activity WHERE lead.id = lead_activity.lead_id AND lead_activity.description = 'assigned'
Somehow, in that statement I also need to do another query which checks to see if that lead is in the activity table again with the description of viewed, and if not, we need to include it in the results.
Does anyone have any ideas how to do this?