Delete specific values from column with where cond

2019-03-17 11:44发布

问题:

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?

回答1:

UPDATE TABLE SET columnName = null WHERE YourCondition


回答2:

You don't want to delete if you're wanting to leave the row itself intact. You want to update the row, and change the column value.

The general form for this would be an UPDATE statement:

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 */


回答3:

UPDATE myTable 
SET myColumn = NULL 
WHERE myCondition


回答4:

You can also use REPLACE().

UPDATE Table SET Column = REPLACE(Column, 'Test123', 'Test')