Question

how can delete "TEST" in message field of posts_comments table

DELETE FROM `posts_comments` WHERE `message` LIKE `TEST`

i want all comments have TEST remove from posts_comments table

Was it helpful?

Solution

Just add MySQL Wildcard '%' in order to simulate Contains operation.

Code:

DELETE FROM `posts_comments` WHERE `message` LIKE '%TEST%'

OTHER TIPS

You need single quotes (not backticks) around the string constant:

DELETE FROM `posts_comments`
    WHERE `message` LIKE 'TEST';

In fact, queries are easier to read without backticks. Only use backticks when necessary -- when using unusual characters in an identifier (anything except alpha, numeric, or underscore) or MySQL reserved words. Then, follow the rule that you never use unusual characters in an identifier. And never use MySQL reserved words.

DELETE FROM posts_comments
    WHERE message LIKE 'TEST';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top