表复制
,对某个sql语句进行效率,我们需要海量数据,可以用此方法创建海量数据。
创建一个表
CREATE TABLE my_table
(id INT,
`name` VARCHAR(32),
sal DOUBLE,
job VARCHAR(32),
deptno INT);
将别的表的数据复制(插入)到表里面
INSERT INTO my_table
(id ,`name`,sal,job,deptno)
SELECT empno,ename,sal,job,deptno FROM emp;
自己复制自己,按多几下
INSERT INTO my_table
SELECT * FROM my_table
SELECT COUNT(*) FROM my_table
演示:
表去重
CREATE TABLE you_table LIKE emp;
INSERT INTO you_table
SELECT * FROM emp;
CREATE TABLE my_temp LIKE you_table
INSERT INTO my_temp
SELECT DISTINCT * FROM you_table
DELETE FROM you_table
INSERT INTO you_table
SELECT * FROM my_temp
DROP TABLE my_temp
SELECT * FROM you_table
合并查询
UNION去重
SELECT ename,sal,job FROM emp WHERE sal>2500 UNION
SELECT ename,sal,job FROM emp WHERE job = 'MANAGER'
UNION ALL不去重