[英]mysql update with data from other table
i been reading and trying alot of the answers to similiar problem. 我一直在阅读和尝试类似问题的答案。 i need to update table test field brand with the content of field name from table brands. 我需要使用表品牌中字段名称的内容来更新表测试字段品牌。 i do this select to check fields that need to be update: 我执行此选择以检查需要更新的字段:
SELECT brand.name,test.`1_name`
FROM test INNER JOIN brand
ON test.`1_name` LIKE CONCAT('%',brand.name,'%')
the above give me a result of 32000 records. 以上给了我32000条记录的结果。 i try to use that select inside an update with 我尝试在更新中使用该选择
UPDATE `test` SET brand=(....)
but couldnt get it to work. 但无法使其正常工作。
Try this : 尝试这个 :
UPDATE `test` SET brand=(SELECT brand.name FROM test INNER JOIN brand ON test.`1_name` LIKE CONCAT('%',brand.name,'%'))
The query you posted returns a collections of data ( SELECT brand.name,test.1_name
... ),
SET brand = ` needs a scalar value. 您发布的查询将返回数据集合( SELECT brand.name,test.1_name
... ),
SET brand =`需要标量值。
In other words, ensure that your query returns only one result. 换句话说,请确保您的查询仅返回一个结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.