I have a real mindbender of a MySQL problem which I am now thinking there is no answer to. Please help me, you are my only hope!

Stripping it down to the basics, I have two tables, "People" and "Activity". It is possible (long story and lots of data involved) for these two tables to be joined by two different relationship tables: people\_activity and entity\_activity
I need to do a query on the activity table which gets the people record/s linked to activity records based on both relationship tables.

This is what I have, but it is massively slow on lots of data:

```
select * from activity 
left join peopleactivity on peopleactivity.activityid = activity.activityid
left join entityactivity on entityactivity.activityid = activity.activityid
left join people on (peopleactivity.peopleid = people.peopleid OR
                     entityactivity.entityid = people.peopleid)

```

Some more notes - I have also tried creating a view to combine the results of the two relationship tables and instead joining people and activity via this view. This also works, but is also still massively slow

Changing how the relationship/s work to consolodate to one table is a major headache

I have also tried a union -like this -

```
select * from activity 
left join peopleactivity on peopleactivity.activityid = activity.activityid
left join people on (peopleactivity.peopleid = people.peopleid) 
union
select * from activity 
left join peopleactivity on peopleactivity.activityid = activity.activityid
left join people on (entityactivity.entityid= people.peopleid) 

```

which also works, but for other reasons causes me problems. I really need to do this in one query without changing too much underlying.

Has anyone got any super amazing ideas that I have missed??!