MariaDB教程

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联合所有运算符1
您可以看到它不会删除重复的记录。

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

使用带有ORDER BY子句的UNION ALL运算符可从两个表中检索多个列。
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联合所有运算符2
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4