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];
SELECT student_name FROM Student UNION ALL SELECT student_name FROM Students;
输出:
您会看到它不会删除重复的记录。
将UNION ALL运算符与ORDER BY子句一起使用可从两个表中检索多个列。
链接:https://www.learnfk.comhttps://www.learnfk.com/mariadb/mariadb-union-all-operator.html
来源:LearnFk无涯教程网
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;
输出:
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)