SQL复制一行然后更新 [英] SQL duplicate a row and then update

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

问题描述

我需要创建一行的副本,然后更新它.

I need to create the duplicate of a row, and then update it.

  NAME      LOCATION    FLAG
  ====      ========    ====
  name1     location1    0
  name2     location2    0

首先我必须选择 NAME = name1 和 LOCATION=location1 的行并创建重复的行,然后用新值更新 NAME 列.

first I have to select the row with NAME = name1 and LOCATION=location1 and create duplicate row and then update the NAME column with new value.

我可以选择行

select NAME,LOCATION,FLAG from TABLE where NAME=name1 and LOCATION=location1

所以结果应该是这样的

  NAME      LOCATION    FLAG
  ====      ========    ====
  name1     location1    0
  name2     location2    0
  name3     location1    0

推荐答案

您可以直接插入您的选择,只需选择您的新名称作为名称列的值

You can directly insert your select and just select your new name as value for the name-column

INSERT INTO TABLE (Name, Location, Flag) 
    select "New Name",LOCATION,FLAG from TABLE where NAME=name1 and LOCATION=location1

这篇关于SQL复制一行然后更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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