Stack Stack - 8 months ago 36
MySQL Question

How can I insert multiple rows in the same table by one query?

I have two insert queries like these:

INSERT INTO mytable VALUES('NULL',name1)('NULL',name2)


Those two
INSERT
queries above, add two separated rows to
mytable
. Well can I do that via single query?

Answer

Use:

INSERT INTO mytable (id, name) VALUES 
(NULL, :name1),
(NULL, :name2)