Reputation: 24325
If someone passes a '%'
to a field that compares in my sql with su.username LIKE CONCAT('%', email ,'%'))
it returns all rows. It ends up looking like su.username LIKE CONCAT('%%%')
. Can I get around this in anyway without filtering out the '%'
?
Upvotes: 1
Views: 121
Reputation: 4995
You need to escape the %, so it literally matches '%'
select * from mytable
where mycol like '%\%%';
Upvotes: 0
Reputation: 324630
I'm assuming you mean you want to escape the %
so it matches a literal %
instead of anything.
In that case, you just need:
... su.username LIKE CONCAT('%',REPLACE(email,'%','\\%'),'%')
Upvotes: 3