简体   繁体   中英

How to update one table in MYSQL from another table?

I have two tables

Table tool column names:

id toolnumber currentduedate  
1    123      11/3/2015  
2    456      11/3/2015 
3    789      11/3/2015

Table event column names:

id  eventnumber  newDuedate
7    123          11/3/2015  
9    123          11/3/2015
10   456          11/3/2015

What i want is when i update the newDuedate in table event it should update the currentduedate in tool table. I am using this query:

mysql_query

UPDATE tool INNER JOIN event SET tool.currentduedate = event.newDuedate WHERE tool.toolnumber = event.eventnumber ;

is working fine but if i have 2 field with the same eventnumber this query update only one. Any ideas?

Try this way

UPDATE tool 
INNER JOIN event on tool.toolNumber = event.eventnumber 
SET tool.currentduedate = event.newDuedate  ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM