I have a people table 'ocp_people', and an address table 'ocp_address', and a table containing lots of 'event participation' codes 'ocp_people_prog'. Each individual should have one address (but not always), and may have lots of event codes. The code at the moment looks like this;
SELECT lk.ppeople_id, lk.pprog_id, pe.surname, pe.citation_form
FROM ocp_people_prog AS lk,
(ocp_people AS pe LEFT JOIN ocp_address AS addr ON pe.people_id=addr.people_id)
WHERE lk.ppeople_id <> ''
AND (lk.pprog_id LIKE 'event1%'
OR lk.pprog_id LIKE 'event2%'
OR lk.pprog_id LIKE 'event3%'
OR lk.pprog_id LIKE 'event4%' )
AND pe.people_id=lk.ppeople_id
GROUP BY pe.people_id ORDER BY pe.surname
This is fine where I want everyone who fits into any category; but how about if I want to collect only those where all criteria apply, or even apply a NOT match?
===================
bloke1 has been to event1, event2, event3
bloke2 has been to event2
bloke3 has been to event1
bloke4 has been to event2, event3
who has been to event1?
= bloke1, bloke3
who has been to event2?
= bloke1, bloke2, bloke4
who has been to event1 AND event2?
= bloke1
who has been to event2 BUT NOT event1?
= bloke2, bloke4
Thus in pseudocode;
CODE
AND lk.pprog_id LIKE 'code1%'
AND lk.pprog_id LIKE 'code2%'
AND lk.pprog_id NOT LIKE 'code3%'
How is it possible to achieve this within a single statement? I can't see any way of achieving the logic of this statement without applying multiple 'AND's, which always give me a '0' selection. Any assistance gratefully received.....