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

I have a column that needs to be updated but must be located through a series of events. The column is for passwords. On an update I need to compare an email address in one table with an email address in another which contains a unique id.

my $sth=$dbh->prepare("Update table1 set password='$newpassword' where + binary table1.emailaddress = binary table2.emailaddress and table2. +uniqueid ='$unique_id'"); $sth->execute();

The variables $newpassword and $unique_id are coming through but table1 is not updating. I looked for examples of updates and found none showing where values across tables were compared. Am I doing something wrong or is this something that won't work?

Replies are listed 'Best First'.
Re: Cross Table Mysql Update
by typomaniac (Novice) on Jul 02, 2012 at 03:13 UTC

    Problem Solved

    Should have dug just a little deeper in the research. I learned something about 'joins' today. Thank you for this site.

      No doubt there are many ways to solve your problem. Others might like to see what your solution is.

      What came to mind for me was not joins but sub-queries. This example from the MySql documentation might give you some ideas:

      Here is an example of a subquery:
      
      SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
      
      In this example, SELECT * FROM t1 ... is the outer query (or outer statement), and (SELECT column1 FROM t2) is the subquery.