Marklitz has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have 2 columns in Table1. I want to crate another table(Table2) having just the values of Column2 of Table1. my Table1 is as:
Column1 Column2 12 13 14 15 16 18 133 122
I want my output for Table2 as:
Column 13 15 18 122
I tried with my code as:
my $sth = $dbh->prepare("INSERT INTO Table1 values (?,?)"); my $newtable = $dbh->prepare("CREATE Table Table2 Column VARCHAR(12)") +; while(<ARGV>) { ..... .. $sth->execute($words[0],$words[2]) or die $DBI::errstr; $newtable ->execute("SELECT Column2 FROM Table1"); {print "$_";} } $sth->finish(); $newtable->finish(); $dbh->disconnect or warn $dbh->errstr;
But still am not able to create another table. Please guide me.. Thanks

Replies are listed 'Best First'.
Re: Create another table
by tirwhan (Abbot) on Mar 05, 2009 at 12:01 UTC

    This is not a Perl question. The SQL on line 2 of your script is wrong, read the documentation for the "CREATE TABLE" SQL statement for your database.


    All dogma is stupid.
Re: Create another table
by bellaire (Hermit) on Mar 05, 2009 at 12:00 UTC
    First, your CREATE TABLE syntax is not correct, you cannot specify values when creating a table. You need to specify the column names and types for the table to be created.

    Second, you can't use bound parameters (e.g. ?) to insert actual SQL code into a query, only values. Bound parameters are escaped into pure strings, and won't be evaluated as statements.
Re: Create another table
by sanku (Beadle) on Mar 05, 2009 at 12:59 UTC
    hi friend, Try this code...
    #!/usr/bin/perl use DBI; $dbh=DBI->connect('DBI:mysql:test','root','root'); $dbh->do("create table tablename1 select column2 from tablename");