0

I am inserting records to MySQL Table using the following Query :

insert into table(field1, field2) values(1,2);

Now again when I want to add data I am using the above query only change data like :

insert into table(field1, field2) values(3,4);

So is there a way using which I can add more data at a time ?

Java Enthusiast
  • 654
  • 7
  • 19
  • possible duplicate of [Inserting multiple rows in mysql](http://stackoverflow.com/questions/6889065/inserting-multiple-rows-in-mysql) and http://dev.mysql.com/doc/refman/5.5/en/insert.html – feeela Jun 02 '14 at 09:37
  • Although this question is duplicate, I feel that this question is better worded and the other question should instead be flagged as duplicate and point to this. – slebetman Jun 02 '14 at 10:10

4 Answers4

1

You can use following query :

INSERT INTO table(field1, field2) VALUES(1,2),(4,5),(7,8);
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
1

Yes, you can just list all the tuples you want to insert in one query, like this:

INSERT INTO table (field1, field2) values (1, 2), (3, 4);

Or you can specify the inserted data by a subquery:

INSERT INTO table (field1, field2)
SELECT field3, field4 FROM table2
WHERE conditions;
Michał Szydłowski
  • 3,261
  • 5
  • 33
  • 55
1

To insert more than one record at once, we can do this, with each set of field values separated by a comma:

 INSERT INTO table
 VALUES
 (field1, field2),
 (field1, field2),
 (field1, field2),
 (field1, field2)...;
Sunil C K
  • 116
  • 5
0

Try this,

INSERT INTO TABLE(field1, field2) VALUES(1,2),
                                        (3,4),
                                        ..... ;
ravikumar
  • 893
  • 1
  • 8
  • 12