MySQL Insert

MySQL Insert

MySQL insert syntax and examples.

MySQL Insert syntax

INSERT INTO table_name (col1,col2) VALUES (val1,val2);

INSERT INTO table_name (col1,col2) VALUES (val1,val2),(val1_2, val2_2),(val1_3, val2_3);

INSERT INTO table_nameA (col1,col2) SELECT * FROM table_nameB;

Insert example

INSERT INTO test1 (id,name) VALUES (1,'abc'); 

INSERT INTO test1 (id,name) VALUES (2,'def'),(3,'ghi'),(4,'jkl');

INSERT INTO test(id, name) SELECT * FROM test1;

SELECT * FROM test;

Query Result

ID NAME
1 abc
2 def
3 ghi
4 jkl