SQL – insert
desc user1;
| id | int(11) | NO | | NULL | | | username | varchar(20) | NO | | NULL | |
insert into user1 (id, username) values (1, ‘user1‘); select * from user1;
insert into user1 (id, username) values (2, ‘user2‘), (3, ‘user3‘); select * from user1;
将一个表中查询到的结果插入到另一个表中
truncate table user1; insert into user1 (id, username) values (1, ‘test1‘); insert into user1 (id, username) values (2, ‘test2‘); insert into user1 (id, username) values (3, ‘test3‘); insert into user1 (id, username) values (4, ‘test4‘); select * from user1; create table tmp ( test_id smallint, test_name varchar(10) );
insert into tmp (test_id, test_name) select id, username from user1 where id > 2; # 注意不需要加 values select * from tmp;
| 3 | test3 | | 4 | test4 |
drop table tmp;