[英]MySQL updating a Boolean field value based on the duplicated appearance of another filed value of the same row from another table
i have a table (inactive) like: 我有一张桌子(无效),如:
email (varchar 50), country, active? 电子邮件(varchar 50),国家/地区有效吗? (2) (2)
and another table (active) like: 和另一个表(活动),例如:
email (varchar 50), country 电子邮件(varchar 50),国家
i want to check if any of the addresses in email column at "active" is also in the "inactive" table and if so so it would update the "active?" 我想检查“活动”中电子邮件列中的任何地址是否也在“非活动”表中,如果是这样,它将更新“活动”吗? column to: 0/1 or yes/no. 列至:0/1或是/否。
update test1
inner join test2
on test1.email = test2.email
set test1.active = 1
;
Try this solution using UPDATE LEFT JOIN: 使用UPDATE LEFT JOIN尝试以下解决方案:
UPDATE inactive i LEFT JOIN active a USING(email)
SET i.`active?` = 1
WHERE a.country IS NOT NULL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.