SQL 从具有 where 条件的列中删除特定值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4732838/
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
Delete specific values from column with where condition?
提问by tina
I want to delete specific values/data from one column with the WHERE condition. Putting in another way, I don't want to delete the complete row. Is it possible?
我想从具有 WHERE 条件的一列中删除特定值/数据。换句话说,我不想删除完整的行。是否可以?
回答by BvdVen
UPDATE TABLE SET columnName = null WHERE YourCondition
回答by JonBaron
UPDATE myTable
SET myColumn = NULL
WHERE myCondition
回答by Damien_The_Unbeliever
You don't want to deleteif you're wanting to leave the row itself intact. You want to updatethe row, and change the column value.
如果您想保持行本身完好无损,则不想删除。您想要更新行,并更改列值。
The general form for this would be an UPDATE
statement:
这种情况的一般形式是一个UPDATE
声明:
UPDATE <table name>
SET
ColumnA = <NULL, or '', or whatever else is suitable for the new value for the column>
WHERE
ColumnA = <bad value> /* or any other search conditions */
回答by Nathan Holmes
You can also use REPLACE().
您也可以使用 REPLACE()。
UPDATE Table SET Column = REPLACE(Column, 'Test123', 'Test')
更新表 SET Column = REPLACE(Column, 'Test123', 'Test')