Solved

SQL Syntax for MySQL

Posted on 2008-10-06
4
174 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
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 500 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 59

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now