Graham
Graham

Reputation: 1155

Deleting partial data from a field in MySQL

I am trying to remove a specific set of data from a MySQL database field, however I am not sure what the best statement would be for this. For example, if I have a data in a field such as...

The use of a secondary password will allow you to gain access to your account from a non-authenticated computer. A non-authenticated computer is any computer that is not your primary computer, an elected authenticated computer or a computer that automatically deletes cookies. <p>This is a test</p>

...and I want to remove <p>This is a test</p> from the field, what statement would be best?

Upvotes: 2

Views: 1074

Answers (1)

tomfanning
tomfanning

Reputation: 9660

I personally would recommend the REPLACE string function: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_replace

UPDATE table SET fieldname = REPLACE(fieldname, '<p>This is a test</p>', '');

Upvotes: 5

Related Questions