Hi all,

I want to insert multiple records into a table using one query.
And my query is

INSERT INTO table2(id,message)
SELECT id FROM table1 WHERE condn,'hello'

but it displays an error....

Can you help me?
Thanx in advance....

jino

hi
Jino

what exactly you want to insert
insert data through forms or from one table to another table.

regards
nickyspace

Hi all,

I want to insert multiple records into a table using one query.
And my query is

INSERT INTO table2(id,message)
SELECT id FROM table1 WHERE condn,'hello'

but it displays an error....

Can you help me?
Thanx in advance....

jino

It might help to post the error here as well.

Notice that you are trying to INSERT two values, id and message, but you are only SELECTING one value, id. Your query should look something like the following:

INSERT INTO table2(id, message) SELECT id, message FROM table1 WHERE some_condition

dear mike,

actually id is from a table ie:from table1 and the message is a variable that is initialize dynamically.

Try this:

INSERT INTO table2(id, message) VALUES((SELECT id FROM table1 where some_condition), 'Hello')

sorry mike.....

there is another problem ...if my subquery returns more than one records it displays an error

You'll have to write this in two queries:

First do the SELECT id FROM table1 WHERE some_condition

Then do the INSERT INTO table2(id, message) VALUES (first_item_from_select, 'Hello 1'), (second_item_from_select, 'Hello 2'), and so on...

This article has been dead for over six months. Start a new discussion instead.