Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL, finding text with two identifiers

Tags:

sql

select

I have some rows in my table that I need to delete.

The rows that must be delete all have strings with two "***" in them, for example "This is a ***example of *** a bad row".

How can I SELECT these rows, so I can check them out and delete them afterwards?

I know I can use SELECT * FROM table WHERE column LIKE '%***%' but that also selects the rows with just one "***" in them (the rows that must be deleted have two "***" in them).

Thanks!

like image 517
Louisa Avatar asked Jun 29 '26 12:06

Louisa


1 Answers

SELECT * FROM table
WHERE column LIKE '%***%***%'

This will, however, also delete any rows where there are three or more "***". If you don't want that, you can do

SELECT * FROM table
WHERE column LIKE '%***%***%'
  AND column NOT LIKE '%***%***%***%'
like image 134
Amadan Avatar answered Jul 01 '26 03:07

Amadan