In my database, there are four types of individuals, youngOrc, oldOrc, youngHuman, oldHuman.
An individual belongs to a type conditional on a date range. Thus, I have tables like this for each type:
youngOrcList ------------------- individual_id, start_date, end_date
This means that the guy with individual_id is a youngOrc between the start and end date. He may be something else outside that range. Similarly, I have a youngHuman table.
Now, the real table of interest that I want to filter is events:
events ------------------ source_individual_id target_individual_id event_date
Events table records all events between two individuals in my realm. I want to filter so that I only select events between youngOrc and youngHuman.
So this is a "nested" condition of sort, where I need both events.source_individual_id IN youngOrcList AND events.event_date BETWEEN youngOrcList.start_date AND youngOrcList.end_date. How to make this work?
(Also, any suggestion regarding a better title would be great. I don't even know what to call this and thus unable to Google effectively.)