简体   繁体   English

如何在mysql中将一个表中的3列复制到另一个表中

[英]How to copy 3 columns from one table into another in mysql

I have two tables and both include 2 columns, sureness and kindness and and they are related to each other by dataitemID and id. 我有两个表,都包括2列,确定性和善意,并且它们通过dataitemID和id相互关联。 Just to show you the structure I will put 2 selects that I got from database: 只是为了向您展示我将从数据库中获取2个选择的结构:

SELECT ID,sureness,kindness FROM omid.tweet  ;

SELECT ID,DataitemID,sureness,kindness FROM omid.entity_epoch_data ;

and I want to copy all value of sureness and kindness in omid.tweet into entity_epoch_data where entity_epoch_data.entityID is equal to entityID coming from entity_relation where tweet.ID =entity_relation.ID 我想在omid.tweet中将所有值的确定性和善意复制到entity_epoch_data中,其中entity_epoch_data.entityID等于来自entity_relation的entityID,其中tweet.ID = entity_relation.ID

I want just to do it in mysql rather than reading the whole table in java and updating the database in the loop but I am so confused. 我只想在mysql中执行它,而不是在java中读取整个表并在循环中更新数据库,但我很困惑。 How can I do that?I appreciate any help:) 我怎么能这样做?我感谢任何帮助:)

Update: 更新:

I wrote the code as follow but it does not work: 我编写了如下代码,但它不起作用:

update tweet, entity_epoch_data
set entity_epoch_data.sureness= tweet.sureness,
entity_epoch_data.kindness = tweet.kindness ,
entity_epoch_data.calmness = tweet.calmness ,
entity_epoch_data.happiness = tweet.happiness 
WHERE entity_epoch_data.EntityID in(
SELECT EntityID FROM omid.entity_dataitem_relation
INNER JOIN omid.tweet t ON entity_dataitem_relation.DataitemID = t.ID)

It's actually pretty straight forward. 它实际上很直接。 The UPDATE clause works like a JOIN and then use SET to set the values UPDATE子句的工作方式类似于JOIN,然后使用SET来设置值

UPDATE tweet INNER JOIN entity_epoch_data
      ON tweet.id = entity_epoch_data.id    
SET entity_epoch_data.sureness= tweet.sureness,
    entity_epoch_data.kindness = tweet.kindness 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM