0

In MySQL my table1 is

ID name parent
1  one   0
2  two   1
3  three 1

and my table2 is

ID name parent
1  com    2,3 -->is table1.ID

I want to relate between table2.parent and table1.id and show tree result :

com -> one -> two,three

How can I query it? I query this:

SELECT  *
from table1 a
left join table1 b on b.parent=a.ID
where b.ID in (2,3)

this work nice but didn't work this:

SELECT  *
from table1 a
left join table1 b on b.parent=a.ID
where b.ID in (select parent from table2)
cn007b
  • 16,596
  • 7
  • 59
  • 74
Mustafa
  • 58
  • 4

1 Answers1

0

try this:

select *
from table2 t2
left join table1 t1 on find_in_set(t1.id, t2.parent) > 0
group by t2.id
;
cn007b
  • 16,596
  • 7
  • 59
  • 74