I have the following tables: tPlans, tPlansProperties, tProperties, tEventsProperties, tEvents.
For these tables there is a many to many relationship between tPlans and tProperties. There is also a many to many relationship between tEvents and tProperties.
I am trying to get all tEvents that have ALL the same tProperties as tPlans, but am running into a dilemma where if there is even one Property that is in both Plans and Events that it shows it as a result. I need to achieve this without hard-coding all the different types of properties or post processing the queried results.
Here is what I have so far:
SELECT
P1.id
,P1.name
,E1.property
,E1.id
,E1.name
FROM (
SELECT
P.id
, P.name
, PP.property
FROM tPlans P
INNER JOIN tPlansProperties PP
ON P.id = PP.id
) P1
INNER JOIN (
SELECT
E.id
, E.name
, EP.property
FROM tEvents E
INNER JOIN tEventsProperties EP
ON E.id = EP.id
WHERE E.id LIKE 'EVT2011SC99'
) E1
ON P1.property = E1.property
here is a high level view of the tables:
tPlans
id,name,type,cost,vendor_id
tPlansProperties
id,property
tProperties
property,property_name,property_type
tEventsProperties
id,property
tEvents
id,name,description,date,owner_id