Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Syntax for MySQL

Posted on 2008-10-06
4
Medium Priority
?
187 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

610 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