Solved

SQL Syntax for MySQL

Posted on 2008-10-06
4
178 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 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