Re: MySQL queries in a relational database
francesca casalino <[email protected]> Thu, 31 Mar 2011 01:27:48 -0700
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
--00504502cc169562fc049fc311c8
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
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 =3D$dbh->prepare("INSERT into frequency (total_count)
SELECT count(genotype.allele_id)
from allele, genotype
where allele.allele_id =3D genotype.allele_id
group by allele.variation_id");
$sth->execute();
$sth->finish;
Thank you for your help again,
-f
2011/3/30 Darren Duncan <[email protected]>
> 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=85i=
f
>> 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 pullin=
g
> your data out to Perl and pushing it in again.
>
> insert into mytbl (mycol1, mycol2)
> select mycol1, mycol2 ... <ordinary select statement continues>
>
> -- Darren Duncan
>
--00504502cc169562fc049fc311c8--