in.md 950 字节
Newer Older
M
in  
Mars Liu 已提交
1 2 3 4 5 6 7
# IN

Joe 想要从员工表

```mysql
create table employee(
    id int primary key auto_increment,
M
Mars Liu 已提交
8
    dept_id int,
M
in  
Mars Liu 已提交
9 10 11 12 13 14 15
    name varchar(256),
    post varchar(16)
)
```

中查询出研发部(dept为'rd')和人力资源部(dept为'hr')的员工列表,这个查询应该怎么写?

M
Mars Liu 已提交
16 17
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
in  
Mars Liu 已提交
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
## 答案

```mysql
select id, dept, name, post 
from employee
where dept in ('dev', 'hr');
```

## 选项

### A

```mysql
select id, dept, name, post 
from employee
where dept in (select 'dev', 'hr');
```

### B

```mysql
select id, dept, name, post 
from employee
where dept in (select * from 'dev', 'hr');
```

### C

```mysql
select id, dept, name, post 
from employee
where dept in ('dev' and 'hr');
```

#### D

```mysql
select id, dept, name, post 
from employee
where dept in ('dev' or 'hr');
```