表格小组成员和小组成员共有1列。叫做user_id,例如,它是整数
表格面板:
---------------------------------------------------------
user_id email name
---------------------------------------------------------
5 hello@dummy.com john
6 man@city.com Ronn
1 fun@dummy.com Sat
表格小组成员:
---------------------------------------------------------
user_id email_active
---------------------------------------------------------
5 1
6 1
1 1
我需要做的是更改电子邮件中包含“ @ dummy.com”的名称 设置为虚拟,并将面板中所有虚拟电子邮件的email_active更改为2而不是1。
我不确定如何做到这一点,我已经设法通过使用以下方法搜索虚拟电子邮件来更改小组成员的姓名
UPDATE panelists SET name = 'dummy' WHERE u_email LIKE '%dummy.com';
但是我不确定如何更新面板表中的email_active。
答案 0 :(得分:2)
您可以从1个查询中更改2个表,如下所示:
UPDATE panel t1, panelists t2
SET t1.email = "dummy", t2.email_active = 2
WHERE t1.user_id = t2.user_id AND t1.email like "%@dummy.com";
但是如果您的表很大(包含许多行),我建议您运行2个独立的查询,例如:
-- step 1
UPDATE panel SET email = "dummy" WHERE email like "%@dummy.com";
-- step 2
UPDATE panelists t1
JOIN panel t2 on t1.user_id = t2.user_id AND t2.email = "dummy"
SET email_active = 2;
答案 1 :(得分:2)
您可以从1个查询中更改2个表,如下所示:
UPDATE panelists as a
JOIN panel as s
ON s.uid = a.uid
SET a.pstatus = '2', s.u_name = 'dummy'
WHERE s.u_email LIKE '%dummy.com';
答案 2 :(得分:1)
UPDATE panelists
SET email_active = '2'
WHERE user_id in (
SELECT user_id
FROM panel
WHERE email LIKE '%dummy.com'
);
这应该可以完成
您也可以像这样使用联接
UPDATE panelists
JOIN panel
ON panelists.user_id = panel.user_id
SET panelists.email_active = '2'
WHERE panel.email LIKE '%dummy.com';