MySQL insert select连用

2021-05-11 20:20:22
共69字 预计阅读1分钟
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CREATE TEMPORARY TABLE one (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
text CHAR ( 4 ) NOT NULL
);
CREATE TEMPORARY TABLE two (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
one_id BIGINT NOT NULL,
text CHAR ( 4 ) NOT NULL
);

INSERT INTO one (text) VALUE ('one1'), ('one2'), ('one3'), ('one4');

SELECT * FROM one;
INSERT INTO two (one_id, text) SELECT * FROM one;
SELECT * FROM two;

DROP TABLE one;
DROP TABLE two;