Dear all,

I have a table in mysql and i want to insert records into the table without using "FOR" or "WHILE" loop..Can this be done??

Thanks in advance..

Jino.

What do you mean by without using for or while loop ? What's the problem in inserting a record directly ? ie., insert into tablename (col1,col2) values ('val1','val2')

not that i want to insert More than 100 records into my database with a single query.... I need this for making the things fast..

Is that possible??

Thanks

If you know the values, you can do something like this.

insert into table (col1) values (val1),(val2),(val3)

This will insert 3 records to the table.

nave it is ok when we enter the records manually and we know the no. of records

Here it is not the case... I have an array having the value of several records that i it got as a result of a query..

I now want to insert these records into an another table without using the while or for loop...
Hope u get me..

Thanks in advance..
Jino.

I am trying to do that without a loop...

cos that will make things done faster..

Pls get back to me if u get any idea about this..

Once again thx
Jino.

I think you can get it done relatively easy by using INSERT ... SELECT.
This is the example found in MySQL Reference Manual:

INSERT INTO tbl_temp2 (fld_id)
  SELECT tbl_temp1.fld_order_id
  FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
This article has been dead for over six months. Start a new discussion instead.