使用条件将行从一个表迁移到另一个表[MYSQL] [英] Migrating row from one table to another with conditions [MYSQL]
本文介绍了使用条件将行从一个表迁移到另一个表[MYSQL]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个MYSQL表:
I have 2 MYSQL TABLES:
TABLE 1:
PRODUCTID | BRAND | BASECOLOR | COLORNAME
Table 2:
PRODUCTID | BRAND | COLORNAME
在表1中,COLORNAME字段为空,字段PRODUCTID必须在两个表中匹配。我需要将行COLORNAME从table2移动到表1.我已经完成了这个SQL请求:
In table 1 the field 'COLORNAME' is empty and the fields 'PRODUCTID' and 'BRAND' must match in the two tables. I need to moove the row 'COLORNAME' from table2 to table 1. I've done this SQL request:
INSERT INTO tablel (COLORNAME) SELECT COLORNAME FROM table2 WHERE table1.PRODUCTID = table2.PRODUCTID AND table1.BRAND = table2.BRAND
我已得到此答案:
未知列'table1.PRODUCTID'在'where子句'
Unknown column 'table1.PRODUCTID' in 'where clause'
我是SQL的新用户,所以我有点失落,我要感谢一些帮助。
I'm new in SQL so I'm a bit lost, I would thank some help.
推荐答案
尝试这样:
update table1 tab1, table2 tab2 set tab1.colorname=tab2.colorname where tab2.brand=tab1.brand;
这篇关于使用条件将行从一个表迁移到另一个表[MYSQL]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文