Mysql数据库(五) union 和union all 连接查询到的两个表的记录
表employees,
表employee_tbl,
union: select emp_no,first_name from employees union select id,name from employee_tbl; 连接两个表中选择的部分,如下图,
如果表中有重复的话,union只列出不重复的部分,如果只挑选名字的话,其中重复的小明和小王等只会出现一次,如下图,上图中出现很多次是因为id不同,所以判断为不同的记录。
union all 则全部列出,不论两个表是否重复,如下图