develooper Front page | perl.beginners | Postings from March 2002

thanks for the response yesterday , but I still dont get it ... Trying not to add dup names in DB

Thread Next
From:
FLAHERTY, JIM-CONT
Date:
March 28, 2002 09:26
Subject:
thanks for the response yesterday , but I still dont get it ... Trying not to add dup names in DB
Message ID:
6D0317C617A8D3119EC000A0C9FC45240190AA65@kinx68322m1.cnet.navy.Mil
I made the column testname unique . But I did quite understand how to change
to query syntax.
Stephen told me  to add where clause "Where IDENTIFIER NOT IN (  SELECT
IDENTIFIER FROM TABLE)"
 
I dont get what he means .. I am new to perl .
 
 
 
the table 
 
show columns from phistory;
+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| num       | int(4)      |      | PRI | NULL    | auto_increment |
| testname  | varchar(60) | YES  | MUL | NULL    |                |
| numpeople | int(6)      | YES  |     | NULL    |                |
| numtimes  | int(6)      | YES  |     | NULL    |                |
| average   | float       | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
 
mysql> 
 
 
 
CODE
 
 
 
 
 
 
my $sth1 = $dbh -> prepare("select distinct testname from testhistory");
$sth1 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 
my $array_ref1 = $sth1->fetchall_arrayref();
 

  foreach $row(@$array_ref1) {
     my($tname) = @$row;
 

   my $sth2 = $dbh -> prepare("insert into
phistory(testname)values('$tname')");
$sth2 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 
 
 
}
 

thanks 
Jim
 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About