children.md 539 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# 查找子节点

有一个表 node,有两列

```shell
# select item from node;
id  | pid
------------------
1   | 0
2   | 1
3   | 1
4   | 3
5   | 2
...   
```

其中id是自增主键,pid指向父节点的id。那么给定某一个id ,查找它的子节点的查询应该是:

## 答案

```sql
select * from node where pid = ?
```

## 选项

### 缺少 where

```sql
select * from node pid = ?
```

### 结构错误

```sql
from node select * where pid = ?
```

### select 不完整

```sql
select from node where pid = ?
```