Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting multiple rows with 1 query

I have problem in inserting multiple rows with 1 query using ms access 2003. When I use INSERT INTO like the code below

INSERT INTO Employee values ('1','b','c');
INSERT INTO Employee values ('2','d','e');  

the problem, ms access always appears pop up characters found after end of SQL Statement. So, are there any way to insert the data into the table?

like image 335
noname Avatar asked Dec 28 '12 05:12

noname


People also ask

How do I insert multiple rows in one query in SQL?

INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.

Is it possible to insert multiple rows simultaneously?

Tip: Select the same number of rows as you want to insert. For example, to insert five blank rows, select five rows. It's okay if the rows contain data, because it will insert the rows above these rows. Hold down CONTROL, click the selected rows, and then on the pop-up menu, click Insert.

Can I insert multiple rows in one query in MySQL?

Insert multiple rows in MySQL with the help of “values”. You can enclose the values with parentheses set with comma separation.


1 Answers

With Access SQL you can't combine two INSERT statements. You could run each of them separately. But if you need to do it with a single statement, you will need to use a more complex query.

INSERT INTO Employee
SELECT '1','b','c'
FROM Dual
UNION ALL
SELECT '2','d','e'
FROM Dual;

Dual is a custom table designed to always contain only one row. You can create your own Dual table using the instructions from this Stack Overflow answer.

However, you don't actually need a custom table for this purpose. Instead of Dual, you can use any table or query which returns only one row.

like image 136
HansUp Avatar answered Oct 09 '22 06:10

HansUp