需要将数据从同一表中的一个字段移到另一个字段 [英] need to move data from one field to another, within the same table

查看:53
本文介绍了需要将数据从同一表中的一个字段移到另一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有数据从field_id_41移到field_id_380,其中weblog_id = 191

I want to move all data from field_id_41 into field_id_380, where weblog_id = 191

这两个字段属于同一表:exp_weblog_data

Those two fields belong to the same table: exp_weblog_data

我不想在这里不问任何事情,我开始将它们放在一起:

I do not want to run anything without asking here, I started to put this together:

UPDATE 
  exp_weblog_data 
SET 
  field_id_380 = (SELECT field_id_41 FROM exp_weblog_data 
  WHERE (field_id_41 != '' and weblog_id = 191)) 
WHERE 
  weblog_id = 191

推荐答案

确实不需要子查询.您可以只取同一行中另一列的值,然后在第一列中进行设置:

Really no need for the subquery. You can just take the value for the other column in the same row, and set it in the first column:

UPDATE 
  exp_weblog_data 
SET 
  field_id_380 =field_id_41 
WHERE 
  weblog_id = 191
AND 
  field_id_41 != ''

这篇关于需要将数据从同一表中的一个字段移到另一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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