我需要更新SQL数据库中某些特定表的列。
我有一个SELECT命令,该命令选择所有正确的表,但我不知道如何将其与UPDATE结合使用(我是一个完整的菜鸟)。
SELECT
c.id_customer AS id_customer,
id_gender,
firstname,
lastname,
c.email AS email,
birthday,
date_add,
c.active AS active,
c.*,
a.id_group
FROM prstshp_customer_group a
LEFT JOIN prstshp_customer c
ON (a.id_customer = c.id_customer)
WHERE 1
AND a.id_group = 4
AND c.deleted != 1
AND c.id_shop IN (1)
ORDER BY id_group ASC
我必须用在表id_default_group
表中选择的特定条目的值“ 4”来更新表prstshp_customer
中名为prstshp_customer_group
的列。
答案 0 :(得分:1)
使用update join
update prstshp_customer
join
(
SELECT
c.id_customer AS id_customer,
id_gender,
firstname,
lastname,
c.email AS email,
birthday,
date_add,
c.active AS active,
a.id_group
FROM prstshp_customer_group a
LEFT JOIN prstshp_customer c
ON (a.id_customer = c.id_customer)
WHERE 1
AND a.id_group = 4
AND c.deleted != 1
AND c.id_shop IN (1)
)B on prstshp_customer.id_customer=B.id_customer
SET id_default_group=4