37

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?

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
tina
  • 371
  • 1
  • 3
  • 3

5 Answers5

59
UPDATE YourTable SET columnName = null WHERE YourCondition
lbragile
  • 7,549
  • 3
  • 27
  • 64
BvdVen
  • 2,921
  • 23
  • 33
27
UPDATE myTable 
   SET myColumn = NULL 
 WHERE myCondition
Mike
  • 14,010
  • 29
  • 101
  • 161
JonBaron
  • 413
  • 3
  • 5
  • If you post code, XML or data samples, **please** highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it! – marc_s Jan 19 '11 at 08:10
19

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 */
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
6

You can also use REPLACE():

UPDATE Table
   SET Column = REPLACE(Column, 'Test123', 'Test')
Mike
  • 14,010
  • 29
  • 101
  • 161
Nathan Holmes
  • 105
  • 2
  • 12
1

Try this SQL statement:

update Table set Column =( Column - your val )
Shankar Ganesh Jayaraman
  • 1,401
  • 1
  • 16
  • 22