使用基于另一个表的条件更新一组列?
我有两张桌子:
table_1 - ControlID、代码、 报告日期、归档日期年龄、 年龄类别等,
table_2 - ControlID、代码、 报告日期、归档日期等,
table_1
中的 ControlID
是外键,而不在 table_2 中。我需要用 table_2 中的 ReportedDate 更新 table_1 中的 ReportedDate,并且 Age 和 AgeCatogory 已计算且正常。
我想更新 table_1 中的这三列,其中 ControlID、FiledDate 和 Code 都是相同的。
到目前为止,我已经:
UPDATE table_1 SET ReportedDate=table_2.ReportedDate, Age='<value>' AgeCategory='<value>'
WHERE table_1.ControlID=table_2.ControlID AND
table_1.FiledDate=table_2.FiledDate AND table_1.Code=table_2.Code
如果有人知道如何解决它???
如有任何帮助,我们将不胜感激...
编辑:
我收到错误消息,指出 MySQL Syntax error at 'FROM ...'
I've two tables :
table_1 - ControlID, Code,
ReportedDate, FiledDate Age,
AgeCategory, etc.,table_2 - ControlID, Code,
ReportedDate, FiledDate etc.,
ControlID
in table_1
is Foreign key whereas not in table_2. I need to update ReportedDate in table_1 with ReportedDate in table_2 and Age and AgeCatogory has been calculated and fine.
I want to update those three columns in table_1, where ControlID, FiledDate and Code in both are identical.
Now far I've :
UPDATE table_1 SET ReportedDate=table_2.ReportedDate, Age='<value>' AgeCategory='<value>'
WHERE table_1.ControlID=table_2.ControlID AND
table_1.FiledDate=table_2.FiledDate AND table_1.Code=table_2.Code
If anyone has the idea of how could it be resolved???
Anyhelp would be appreciated...
EDIT:
I'm getting error saying MySQL Syntax error at 'FROM ...'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UPDATE 语法中不允许使用 FROM 1:
如果如果您想从第二个表中获取内容,您可能需要使用子查询。
试试这个代码:
There is no FROM allowed within the UPDATE syntax 1:
If you like to fetch content from a second table, you might want to use a subquery.
Try this code: