![]() |
| ||
| MySql insert 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 |
| ||
| Re: MySql insert hi Jino what exactly you want to insert insert data through forms or from one table to another table. regards nickyspace Quote:
|
| ||
| Re: MySql insert 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 |
| ||
| Re: MySql insert dear mike, actually id is from a table ie:from table1 and the message is a variable that is initialize dynamically. |
| ||
| Re: MySql insert Try this: INSERT INTO table2(id, message) VALUES((SELECT id FROM table1 where some_condition), 'Hello') |
| ||
| Re: MySql insert Thank you mike.....i got it.... |
| ||
| Re: MySql insert sorry mike..... there is another problem ...if my subquery returns more than one records it displays an error |
| ||
| Re: MySql insert 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... |
| All times are GMT -4. The time now is 8:42 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC