mysql update和select连用语句
mysql update和select连用语句
UPDATE t_product_company_record b
inner join (
select (
SELECT
id
FROM
t_product_user
WHERE
username = SUBSTRING(
t.content,
1,
LOCATE('注册了', t.content) - 1
)
) AS userid,
t.id
FROM
t_product_company_record t) c on b.id=c.id
SET b.userid = c.userid where isnull(b.userid)
需求:
默认我company_record这张表userid为空,需要用content内容中的用户名去用户表匹配,拿到id赋值到这张表的userid这一列。