Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a percent (%) in a LIKE without it being treated as a wildcard?

Tags:

mysql

sql-like

I have a database that is supposed to contain all top-level and second-level domain names. But the feed I'm parsing contains a lot of sub folders, I'd like to delete any row that contains any % sign in it, but I am having a hard time figuring out how to use a percent sign as the field I'd like to match, while still using the LIKE feature. Below is the code I'm trying to use:

select FROM `001ProductList` WHERE programURL  LIKE '%%%'

Here is an example of what I'm trying to match:

www.site.com%3Ack-5941560-10463497?url=http%3A%2F%2Fwww.example.com%2Fproddetail.aspx%...

If I encounter a row with a % sign in it, I want to delete it.

like image 358
Robert82 Avatar asked Nov 03 '13 04:11

Robert82


1 Answers

Escape the literal % character:

select * 
FROM 001ProductList
WHERE programURL LIKE '%\%%'

or use regex

WHERE programURL RLIKE '%'
like image 163
Bohemian Avatar answered Oct 16 '22 06:10

Bohemian