mysql - SQL Query with "feedback loop" -
currently, using mysql
i have 2 tables:
table objects:
| id | desc | | 1 | 'a' | | 2 | 'b' | | 3 | 'c' | | 4 | 'd' | | 5 | 'e' |
table implies:
| id1 | id2 | | 1 | 2 | | 1 | 3 | | 2 | 4 | | 2 | 5 | | 3 | 5 |
table implies columns id1 , id2 both foreign keys table objects id.
which means:
object 1 implies object 2 , object 3.
object 2 implies object 4 , object 5
object 3 implies object 5
therefore, object 1, implies 2, 3, , 4 , 5 (since 2 implies 4 , 5)
is there way create query behaviour? current solution consists on calling recursively java query until don't new info:
sql query im calling:
select o.id, i.id2 objects o inner join implies on o.id = i.id1 id = 1;
i first call id = 1, id in (2, 3)... etc
the kind of result want achieve:
select ... id = 1
should return:
| id | id2 | | 1 | 2 | | 1 | 3 | | 1 | 4 | | 1 | 5 |
Comments
Post a Comment