mysql 两个关联表如何更新其中一个表的数据
假设:
update B,A set B.memo=A.memo
where A.order_id=B.order_id and (B.memo is null or B.memo=‘‘);
create table A ( order_id int not null auto_increment, operator varchar(50), oper_date date, memo varchar(50), primary key(order_id) ); create table B ( order_id int not null auto_increment, good_id int, good_code int, good_name varchar(50), memo varchar(50), primary key (order_id) ); insert into A values (1,‘onion2‘,now(),‘测试1‘), (2,‘onion2‘,now(),‘测试2‘), (3,‘onion3‘,now(),‘测试3‘); insert into B values (1,1,0001,‘good1‘,‘已经备注‘); insert into B (order_id,good_id,good_code,good_name) values (2,2,0002,‘good2‘), (3,3,0003,‘good3‘); update B,A set B.memo=A.memo where A.order_id=B.order_id and (B.memo is null or B.memo=‘‘);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。