MySQL database on those things "associated with multi-table update"

  We often associate multi-table queries in a query in sql in common with the more skilled. Today met a real business scenario in the development of multi-table related updates, at a loss. Multi-line attitude of learning, there is no direct write java code to achieve, and finally the associated multi-table update sql figured out. The actual business scenarios below to simplify, respectively person table and the information table, the ultimate goal is to update the information in the table to the age of each person's age person table. They were written several sql demo to the multi-table update thorough understanding of knowledge.

  First, before updating, person information table and the table are as follows:

information table

 person table

1. CASE1

  sql :update information,person SET information.phone='13812345678',person.age = '18' WHERE information.name = person.name

  Updated table and the person information table are as follows

         

  Of course, there is a way to achieve the above functions

  sql:UPDATE information JOIN person on information.name = person.name SET information.phone='13811111111',person.age = '18'

  or

  sql:UPDATE information LEFT JOIN person on information.name = person.name SET information.phone='13811111111',person.age = '18'

2.  CASE2  

  sql:UPDATE information RIGHT JOIN person on information.name = person.name SET information.phone='13922222222',person.age = '19'

  Updated table and the person information table are as follows

      

 3.  CASE3

  sql:  UPDATE information JOIN person on information.name = person.name SET information.age=person.age

     

 

   Through the above few examples, I believe that analysis of a number of related updates should be more thorough. More learning, more growth.

 

Guess you like

Origin www.cnblogs.com/Demrystv/p/11762184.html