MySQL 如何将数据添加到现有表中的特定列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4731087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add data to particular column in exisiting table?
提问by aron n
How can I insert data to only one column in an existing table?
如何仅将数据插入现有表中的一列?
I dont want other column get disturbed or altered..
我不希望其他专栏受到干扰或改变..
回答by jerhinesmith
I think you're looking for an update query:
我认为您正在寻找更新查询:
UPDATE
table_name
SET
column = 'value';
That will only "insert" data into a single column while leaving everything else undisturbed.
这只会将数据“插入”到单个列中,而其他所有内容都不受干扰。
If you want to update from the results of another table, you can also do joins:
如果你想从另一个表的结果更新,你也可以做连接:
UPDATE
table_name
INNER JOIN source_table ON
table_name.some_id = source_table.some_id
SET
table_name.column = source_table.column;
Hope that helps. You might want to try clarifying the question with some more information.
希望有帮助。您可能想尝试使用更多信息来澄清问题。
回答by RichardTheKiwi
If you mean "insert" as in "update" then
如果你的意思是“插入”就像“更新”那样
# to a fixed value
update tbl set col = "abc"
# WHERE <some condition> # optionally identify which record
# add to existing value
update tbl set col = concat(col, "abc") # add "abc" to the end of the current value
# WHERE <some condition> # optionally identify which record