On 4/26/05, Jonathan Mangin <[EMAIL PROTECTED]> wrote: > I would like to select several rows from one table > and insert them into another nearly identical table > using Perl/DBI: > > my @array = $q->param(); # HTML checkboxes > > foreach my $element (@array) { > my $sql = "select col2, col3, col4 from table1 > where col1 = ?"; > my $sth = $dbh->prepare($sql); > $sth->execute($element) or die $sth->errstr(); > > my @row = $sth->fetchrow_array; > > $sql = "insert table2 (col1, col2, col3, col4) > values (NULL, ?, ?, ?)"; > $sth = $dbh->prepare($sql); > $sth->execute($row[0], $row[1], $row[2]) or die $sth->errstr(); > } > > Is this efficient db interaction, or is there a better way? > This is 3.23 but can upgrade if necessary.
Is there any reason you didn't just simply do: INSERT INTO table2 (col1,col2,col3,col4) SELECT NULL, col2, col3 col4 FROM table1; ...which is what SQL was made for in a first place. :) If there is a reason, then I am sorry, I just didn't see it in the mail. I just don't understand why sometimes people go at lengths to reimplement SQL in other languages like perl. Regards, Dawid I've seen things that you people wouldn't believe, I watched perl making SELECT on two tables, then "join" the results using perl's hash keys. All these moments will be lost, like tears in the rain... ;) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]