0 votes
1 view
by (14.6k points)
edited by

I have multiple set of data to insert at once, say 4 rows.

My table has three columns: Person, Id and Office.

INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");

INSERT INTO MyTable VALUES ("Jane", 124, "Lloyds Office");

INSERT INTO MyTable VALUES ("Billy", 125, "London Office");

INSERT INTO MyTable VALUES ("Miranda", 126, "Bristol Office");

Can I insert all 4 rows in a single SQL statement?

1 Answer

0 votes
by (72.4k points)

You can use the following SQL query to insert multiple rows just using a single INSERT statement:

INSERT INTO MyTable (Person, Id, Office) VALUES

( Value1, Value2, Value3 ), ( Value1, Value2, Value 3)

INSERT INTO MyTable (Person, Id, Office)

VALUES ('John', 123, 'Lloyds Office'),

               ('Jane', 124, 'Lloyds Office'),

               ('Billy', 125, 'London Office')

You can check out this SQL Tutorial to understand how to use the INSERT statement.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...