考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

在以下语句中,哪个语句可以合并t1与t2表,且不包含合并的重复项
A. select * from t1 union all select * from t2;
B. select * from t1 union select * from t2;
C. select * from t1 union t2;
D. select * from t1 union all t2;
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

本题考查SQL语句中表的合并方法。其中union all保留合并后的重复项,而union则不包含合并的重复项,又因为合并的两边必须是两个表,C和D中的t2只是代表表名,故有语法错误,所以正确答案为B。

在给定的选项中,正确的语句是 B: `select * from t1 union select * from t2;`。

分析如下:

A: `select * from t1 union all select * from t2;`
- `UNION ALL` 会合并两个表的数据,但不会去除重复项。因此,这个选项不符合要求。

B: `select * from t1 union select * from t2;`
- `UNION` 会合并两个表的数据,并自动去除重复项。这正是题目要求的合并方式,因此这是正确答案。

C: `select * from t1 union t2;`
- 这个语法是不正确的。`UNION` 是一个操作符,需要完整的 `SELECT` 语句来合并,不能直接用在表名之间。

D: `select * from t1 union all t2;`
- 这个语法也是不正确的。`UNION ALL` 需要两个完整的 `SELECT` 语句来合并,不能直接用在表名之间。

综上所述,选项 B 正确地使用了 `UNION` 来合并两个表的数据,并去除了重复项。