I’m trying to think of a solution to a mapping problem in which I can relate two seemingly unrelated groups. So, lets say I have a set of attributes, A, an Entity Group 1, and an Entity Group 2. I could easily have a many-many relationship between 1 and A and do queries like
select * from 1
inner join a_1 on a_1.1_id = 1.id
inner join a on a.id = a_1.a_id
where a.attr = '123'
I could obviously do something similar with A related to 2. What I’m trying to actually query though is A to 2 and A to 1 where the elements in group 1 and 2 share the same attribute in A. So, if the attribute I’m storing is an address, I want to be able to select out all people in group 1 and group 2 that share addresses, and what those addresses are.
Appreciate the help!
EDIT:
Table structure:
t1 -----< t1_A >------ A ------< t2_A >------ t2
t1[id, other], t1_A[id, t1id, Aid], A[id, address], t2_A[id, t2id, Aid], t2[id, other]
And the goal is to get a row returned for every element in t1 that has the same address as an element in t2(as well as what that address is).
I think you are looking for
UNION:Update:
Considering the tables’ structures, after updating your question:
t1:
id,t1_A:
id,t1id,Aid,A:
id,address,t2_A:
id,t2id,Aid,t2:
id,So, you want to get:
Then you can do this: