从表 2 更新表 1 [英] Update Table1 From table 2

查看:41
本文介绍了从表 2 更新表 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有两个表,我想从 Table 2

I have two tables in my database and I want to update Table 1 from Table 2

表 1 如下所示:

id - eventid - hostname   - trigger - startime      - endtime  
1     00001  - 10.10.10.1 - PROB    - 2017-08-03 18:33  ?
2     00001  - 10.10.10.1 - PROB    - 2017-08-05 00:33  ?
3     00001  - 10.10.10.1 - PROB    - 2017-08-05 00:32  ?
4     00002  - 10.10.10.2 - PROB    - 2017-08-02 14:58  ?
5     00002  - 10.10.10.2 - PROB    - 2017-08-07 17:59  ?
.
.

表 2 如下所示:

id - eventid - hostname   - trigger - startime       
1     00001  - 10.10.10.1 - OK    - 2017-08-03 19:22  
2     00001  - 10.10.10.1 - OK    - 2017-08-05 03:13  
3     00001  - 10.10.10.1 - OK    - 2017-08-05 04:30  
4     00002  - 10.10.10.2 - OK    - 2017-08-02 15:08  
5     00002  - 10.10.10.2 - OK    - 2017-08-07 19:29
.
.

我如何更新 Table 1 以便我可以将 starttimeTable 2 插入到 endtime 上的 >表1?

How can I update Table 1 so I can insert startime from Table 2 into endtime on Table 1?

推荐答案

您可以在 UPDATE 查询中加入这两个表(在 文档):

You can join the two tables in your UPDATE query (read about it in the documantation):

UPDATE `Table 1` t1
    JOIN `Table 2` t2 ON t1.ID = t2.ID
SET t1.endtime = t2.starttime

这篇关于从表 2 更新表 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆