MySQL multi-Table update example

Source: Internet
Author: User

How can I implement MySQL multi-Table update? Many new users who are new to MySQL databases will have such questions. The following describes the MySQL multi-Table update method for your reference.

MySQL multi-Table update:

 
 
  1. update contact c, contactdroit cd   
  2. set c.user_name = '$username', c.nom = '$lastname', c.prenom = '$firstname', c.passcode = '$password', cd.droit_id = '$droitid'   
  3. where c.contact_id = '$id' and c.contact_id = cd.contact_id;  

Example:

 
 
  1. mysql> create table one(id int(10), name varchar(20));  
  2. Query OK, 0 rows affected (0.03 sec)  
  3.  
  4. mysql> create table two(id int(10), name varchar(20));  
  5. Query OK, 0 rows affected (0.05 sec)  
  6.  
  7. mysql> insert one value(1, '1');  
  8. Query OK, 1 row affected (0.00 sec)  
  9.  
  10. mysql> insert two value(22, '22');  
  11. Query OK, 1 row affected (1.02 sec)  
  12.  
  13. mysql> update one o, two t set o.name='oo', t.name='tt';  
  14. Query OK, 2 rows affected (0.00 sec)  
  15. Rows matched: 2 Changed: 2 Warnings: 0  
  16.  
  17. mysql> select * from one;  
  18. +------+------+  
  19. | id   | name |  
  20. +------+------+  
  21. |    1 | oo   |  
  22. +------+------+  
  23. 1 row in set (0.00 sec)  
  24.  
  25. mysql> select * from two;  
  26. +------+------+  
  27. | id   | name |  
  28. +------+------+  
  29. |   22 | tt   |  
  30. +------+------+  
  31. 1 row in set (0.00 sec)  
  32.  

Mysql multi-Table query implementation

Mysql temporary table usage

MySQL Stored Procedure for table splitting

In-depth discussion on MySQL Lock Mechanism

Implementation of MySQL fuzzy query with multiple fields in a single table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.