Ah yes, that makes things a lot more difficult.
Let’s see here… this should do the trick. I read your post a few times to make sure I had the right idea, and I believe I’ve got something that fits your problem. Also, you seem to understand the custom fields and field ids, so I’ll get right to the meat of the query:
{exp:query sql="
SELECT cd.entry_id AS queried_entry_id
FROM exp_channel_data AS cd
INNER JOIN exp_relationships AS r1 ON cd.field_id_[HOME_REL_FIELD_ID]=r1.rel_id
INNER JOIN exp_relationships AS r2 ON cd.field_id_[AWAY_REL_FIELD_ID]=r2.rel_id
WHERE r1.rel_child_id IN
(SELECT entry_id
FROM exp_channel_data
WHERE field_id_[TEAM_NAME_FIELD_ID]='[TEAM NAME]')
OR r2.rel_child_id IN
(SELECT entry_id
FROM exp_channel_data
WHERE field_id_[TEAM_NAME_FIELD_ID]='[TEAM NAME]')
"}
{exp:channel:entries entry_id="{queried_entry_id}" dynamic="off"}
<h1>{title}</h1>
{/exp:channel:entries}
{/exp:query}
Here it is in english:
give me the entries where the home_team is in (
give me all entries where the team name == “xxxx”
) OR the away_team is in (
give me all entries where the team name == “xxxx”
)
Also, you’ll notice that inner query occurs twice… I’m sure there’s a way to run it only once, but I can’t think of it at the moment.