【发布时间】:2015-07-31 20:40:16
【问题描述】:
我正在将一个表中的一列值插入到另一个表中。我有以下两张表。
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 插入到表-a 列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支持连接,所以update a set a.tags=b.tags join ...
标签: mysql database sql-update sql-insert