Link to home
Start Free TrialLog in
Avatar of pda4me
pda4me

asked on

SQL Syntax for MySQL

I am currently using the following SQL statement thru MyPHPAdmin to update records in the table affiliates.  How do I make this table perform the same operation on TableB and TableC without re-issuing the command and changing the table name each time?

UPDATE affiliates
SET IMSLogin = memberNumber
WHERE IMSLogin = ""
ASKER CERTIFIED SOLUTION
Avatar of MMDeveloper
MMDeveloper
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trickyidiot
trickyidiot

UPDATE
  affiliates,
  TableB
SET
  affiliates.IMSLogin=affiliates.memberNumber,
  TableB.IMSLogin = TableB.memberNumber
WHERE
  affiliates.IMSLogin = TableB.IMSLogin
  AND IMSLogin = '';
The above will only work in MySQL - most databases won't allow this.
Avatar of Kevin Cross
For what it is worth, you can create a trigger that after one is updated updates the others if there is a link between the tables.  If not, then put the code you accepted in a procedure and so you only ever have to run one statement with memberNumber as parameter.

Here is the syntax on triggers: http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html