个性化阅读
专注于IT技术分析

MariaDB UNION ALL运算符

点击下载

本文概述

MariaDB UNION ALL运算符与UNION运算符相同, 但不会删除重复的记录。它返回查询中的所有行, 并且不会删除各个SELECT语句之间的重复行。

句法:

SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
UNION ALL
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];

注意:在MariaDB UNION ALL运算符中, 每个SELECT语句在具有相似数据类型的结果集中必须具有相同数量的字段。


使用UNION ALL运算符返回单个字段

SELECT student_name
FROM Student
UNION ALL 
SELECT student_name
FROM Students;

输出

MariaDB Union ALL运算符1

你可以看到它不会删除重复的记录。


带有ORDER BY子句的UNION ALL运算符

使用UNION ALL运算符和ORDER BY子句从两个表中检索多个列。

SELECT student_id, student_name
FROM Students
WHERE student_name = 'Komal'
UNION ALL 
SELECT student_id, salary
FROM Student
WHERE student_id > 4
ORDER BY 1;

输出

MariaDB Union All运算符2
赞(0)
未经允许不得转载:srcmini » MariaDB UNION ALL运算符

评论 抢沙发

评论前必须登录!