?
Solved

SQL Syntax for MySQL

Posted on 2008-10-06
4
Medium Priority
?
184 Views
Last Modified: 2013-12-12
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 = ""
0
Comment
Question by:pda4me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 2000 total points
ID: 22651128
you can issue mutiple statements at a time,, granted this may not be what you want.. in the SQL textarea, just do this


UPDATE affiliates SET IMSLogin = memberNumber WHERE IMSLogin = "";
UPDATE TableB SET IMSLogin = memberNumber WHERE IMSLogin = "";
UPDATE TableC SET IMSLogin = memberNumber WHERE IMSLogin = "";


it will run all 3
0
 
LVL 6

Expert Comment

by:trickyidiot
ID: 22651291
UPDATE
  affiliates,
  TableB
SET
  affiliates.IMSLogin=affiliates.memberNumber,
  TableB.IMSLogin = TableB.memberNumber
WHERE
  affiliates.IMSLogin = TableB.IMSLogin
  AND IMSLogin = '';
0
 
LVL 6

Expert Comment

by:trickyidiot
ID: 22651296
The above will only work in MySQL - most databases won't allow this.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22651725
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
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question