Today encountered a customer data update problem, two related tables, a main table is used to hold the main information of the document, a sub-table is used to save the document details; Now you want to update the data from one of the fields in the main table to a field in the secondary table.
Hypothesis: A table is the main table, there is a number order_id, open single operator, open a single date Oper_date, Memo memo, etc. b is a sub-table, there is a ticket order_id, serial ID, product code code, name name, Memo memo and so on. The note of a table has data, B table notes no data, now to update the table a data to B table, and B table has data can not be updated. A and B tables are linked by a ticket number. The SQL syntax for updating data is as follows:
Update B,a Set B.memo=a.memo
where a.order_id=b.order_id and (B.memo is null or b.memo= ");
Create TableA (order_idint  not NULLauto_increment, operatorvarchar( -), Oper_date date, Memovarchar( -),    Primary Key(order_id));Create TableB (order_idint  not NULLauto_increment, good_idint, Good_codeint, Good_namevarchar( -), Memovarchar( -),    Primary Key(order_id));Insert  intoAValues (1,'Onion2', now (),'Test 1'),(2,'Onion2', now (),'Test 2'),(3,'Onion3', now (),'Test 3');Insert  intoBValues(1,1,0001,'good1','already notes');Insert  intoB (Order_id,good_id,good_code,good_name)Values (2,2,0002,'good2'),(3,3,0003,'good3');UpdateB,aSetB.memo=A.memowherea.order_id=b.order_id and(B.memo is NULL orB.memo="');
MySQL Two association tables how to update data for one table