asprin
asprin

Reputation: 9833

mysql LIKE operator not matching the condition appropriately

I'm using a query such as

SELECT * FROM tablename WHERE token LIKE 'v_%'

This is resulting in records whose token starts with v_ (which is exactly what I want) but it is also showing records which start with just v (screenshot attached)

enter image description here

Why is this happening? Am I missing something?

Upvotes: 1

Views: 571

Answers (1)

John Woo
John Woo

Reputation: 263893

you need to _ because it is a wildcard

SELECT * FROM tablename WHERE token LIKE 'v\_%'

or

SELECT * FROM tablename WHERE token LIKE 'v|_%' ESCAPE '|';

Upvotes: 4

Related Questions