将数据从一个字段复制到每一行的另一字段 [英] Copy data from one field to another on every row
问题描述
所以我得到了:
id number
1 0
2 0
3 0
是否存在一条sql语句,用于将所有内容从id复制到数字?
Is there a sql statement to copy everything from id into number?
我要编写一个php scrip进行选择,然后更新每一行.我的SQL知识很基础,但是我敢肯定有一种聪明的方法可以做到这一点:
I'm about to write a php scrip to select, then update every row. My SQL knowledge is pretty basic, but I'm sure there's a smart guy way to to do this:
背景:ID过去一直是应用程序中显示的数字,并且是唯一的.该数字不再具有我要添加的一些新功能的唯一性,因此我需要将其移到不唯一的字段中,同时保持旧的完整性.
Background: The id used to be a number that was displayed in the app and was unique. That number is no longer unique with some new features I'm adding--so I need to move it to a field that isn't unique while maintaining the integrity of the old.
推荐答案
您可以使用update语句并引用这些列.只需执行以下操作:
You can use an update statement and reference the columns. Just do the following:
update mytable set number = id
在每一行上将数字设置为等于id.享受吧!
That sets number equal to id on each row. Enjoy!
这篇关于将数据从一个字段复制到每一行的另一字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!