我有带有父子关系的数据库表,例如:
ID         Name         ParentID
-------------------------------------
1         Computer          0
2         Software          1
3         Hardware          1
4         Windows           2
5         Games             0
6         Windows           5
7         Linux             5
8         3D                6
9         DirectX           8
我想在这张表上搜索单词“Windows”,我想要的结果如下:
ID         Name         ParentID
-------------------------------------
1         Computer          0          <== Grandparent of 4
2         Software          1          <== Parent of 4
4         Windows           2          <== 4
5         Games             0          <== Parent of 6
6         Windows           5          <== 6
我的意思是所有与搜索词有关系的父母都应该保留,其余的应该从记录中删除