SQL union all 不去重

创建表(牛客sql108改)

DROP TABLE IF EXISTS `Products`;
CREATE TABLE IF NOT EXISTS `Products` (
    prod_name VARCHAR(255) NOT NULL COMMENT '产品名称'
);
INSERT INTO `Products` VALUES ('a'),('b'),('c');

DROP TABLE IF EXISTS `Customers`;
CREATE TABLE IF NOT EXISTS `Customers`(
    cust_name VARCHAR(255) NOT NULL COMMENT '客户姓名'
);
INSERT INTO `Customers` VALUES ('a'),('b'),('c'),('d'),('e');
Products表

Customers表 

 union 去重

select *
from Products
union
select *
from Customers

 union all 不去重

select *
from Products
union all
select *
from Customers

posted @ 2023-11-11 16:43  Cherlie  阅读(28)  评论(0编辑  收藏  举报