[英]Inserting values into column from another table in MySQL
我正在将一个列值从一个表插入到另一个表。 我有以下两个表。
Table - a
ID Entry_date weight height TagsA
111 1968-07-31 22 34
111 1968-12-31 34 37
112 1969-03-31 8 43
112 1969-07-31 45 48
113 1970-09-30 67 94
113 1973-03-31 23 76
Table - b
ID Entry_date TagsB
111 1968-07-31 1
111 1968-12-31 1
112 1969-03-31 0
112 1969-07-31 0
113 1970-09-30 0
113 1973-03-31 1
这两个表在44300左右具有相等的行数。两个表的ID和Entry_date列相同。 我想插入表-b列TagsB中的所有值到表-列TagsA中。 因此,结果表应如下所示:
Table - a
ID Entry_date weight height TagsA
111 1968-07-31 22 34 1
111 1968-12-31 34 37 1
112 1969-03-31 8 43 0
112 1969-07-31 45 48 0
113 1970-09-30 67 94 0
113 1973-03-31 23 76 1
我尝试使用更新:
update a set TagsA = (select TagsB from b where a.ID = b.ID and a.Entry_date = b.Entry_date);
Error Code: 1242. Subquery returns more than 1 row 714.523 sec
在这种情况下如何进行?
试试这个:
update a set TagsA = (select max(TagsB)
from b
where a.ID = b.ID and a.Entry_date = b.Entry_date);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.