Ryan
Ryan

Reputation: 15270

How can I query all results matching a simple substring in MySQL?

This should be so simple but I must be missing something obvious.

Table:

id    name
===============
1     Allison
2     BethAnn
3     Carly
4     MaryAnn

Test Query:

SELECT id,SUBSTRING(name,5) FROM my_table;

Result:

1    son
2    Ann
3    y
4    Ann

Great. Now just get the id's where the characters 5+ = 'Ann':

SELECT id FROM my_table WHERE SUBSTRING(name,5) = 'Ann';

Expected Result:

2
4

Instead I get nothing. What am I missing?

Waiting for facepalm. Thanks in advance.

Upvotes: 0

Views: 219

Answers (1)

jsist
jsist

Reputation: 5253

Your query is correct and producing correct results for me. There seems to be something other that is causing problem. Here is the screenshot...

enter image description here

Hope it helps...

Upvotes: 1

Related Questions