List:MySQL and Perl« Previous MessageNext Message »
From:francesca casalino Date:March 31 2011 8:27am
Subject:Re: MySQL queries in a relational database
View as plain text  
Hi Duncan,
Thank you for the hint about doing the insert and select in one step. I
tried that but it is not inserting any records, and it does not give me an
error message.
This is what I am doing:

#count number of alleles entered for each variation:

my $sth =$dbh->prepare("INSERT into frequency (total_count)
SELECT count(genotype.allele_id)
from allele, genotype
where allele.allele_id = genotype.allele_id
group by allele.variation_id");
$sth->execute();
$sth->finish;

Thank you for your help again,
-f

2011/3/30 Darren Duncan <darren@stripped>

> francesca casalino wrote:
>
>> I am now having trouble with generating a query in Perl DBI to take data
>> from this database and insert it into another table in MySQL; I am still
>> just at the start in learning both MySQL and Perl, and sorry if this is a
>> simple question again, but I have been stuck on this for a while now…if
>> you
>> have any advice on how to tackle this please let me know.
>>
>
> I don't know if you're already doing this, but you may be able to do your
> SELECT and INSERT as a single SQL statement, which is simpler than pulling
> your data out to Perl and pushing it in again.
>
>  insert into mytbl (mycol1, mycol2)
>  select mycol1, mycol2 ... <ordinary select statement continues>
>
> -- Darren Duncan
>

Thread
MySQL queries in a relational databasefrancesca casalino30 Mar
  • Re: MySQL queries in a relational databaseMichael R Boudreau30 Mar
    • Re: MySQL queries in a relational databasefrancesca casalino30 Mar
  • Re: MySQL queries in a relational databaseDarren Duncan30 Mar
    • Re: MySQL queries in a relational databasefrancesca casalino31 Mar
      • Re: MySQL queries in a relational databaseDarren Duncan31 Mar
        • Re: MySQL queries in a relational databasefrancesca casalino31 Mar