提交 e14884d6 编写于 作者: M Mars Liu

add join

上级 a0ad53cd
{
"type": "code_options",
"author": "刘鑫",
"source": "show_title.md"
}
\ No newline at end of file
# 显示分类标题
假设员工表employee和部门表department中有如下列:
```sql
create table employee(
id integer auto_increment primary key ,
name varchar(256),
dept int
);
create table department(
id integer auto_increment primary key ,
name varchar(256)
)
```
员工表的 dept 列引用 department 表的主键。
那么能够显示员工列表,并展示其所在部门的名称的是:
## 答案
```sql
select e.id, e.name, d.name as department
from employee as e join department as d on e.dept = d.id
```
## 选项
### 表名引用错误
```sql
select e.id, e.name, d.name as department
from employee as e join department as d on e.dept = d.id
```
### 连接条件错误
```sql
select e.id, e.name, e.name as department
from employee as e join department as d on e.id = d.id
```
### 连接条件错误
```sql
select e.id, e.name, e.name as department
from employee as e join department as d on e.department in d.id
```
### 列名存在歧义问题
```sql
select e.id, name, d.name as department
from employee as e join department as d on e.dept = d.id
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册