Stack Stack - 6 months ago 20
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)
Comments