用于父子的Mysql查询

时间:2012-01-18 07:26:53

标签: mysql

  id   child    parent
   1    26       1
   2    25       1
   3    27       26
   4    28       45

我需要得到parent = 1的所有孩子以及孩子的子孩子 查询返回1,26,25,27

1 个答案:

答案 0 :(得分:0)

尝试以下

select * from myTable where parent IN (select child from parent where parent=1) OR parent = 1

祝你好运,希望这就是你想要的......

相关问题