Yashawant Sawant
Yashawant Sawant

Reputation: 43

Mysql LIKE or REGEXP

I am trying to select all the strings has word ABC1 in it. But getting wrong answer with LIKE query. Not sure how to get exact answer.

Below is the string format in a column:

"SomeString ABC1000 Other";

And I don't want to select any String which is in the format like
"itisABC1000 other other"

Upvotes: 0

Views: 37

Answers (2)

Yashawant Sawant
Yashawant Sawant

Reputation: 43

Found answer with LIKE

select column
from table
where conditions like "% ABC1%" or conditions like "ABC1%";

Thank you!

Upvotes: 0

nbk
nbk

Reputation: 49403

with reular expression you can use REGEXP\_LIKE

this oirks for MYsql 8.x

select REGEXP_LIKE("SomeString ABC1000 Other",'ABC1')
REGEXP_LIKE("SomeString ABC1000 Other",'ABC1')
1

fiddle

Your query would wlook like

SELECT yourcolmuns FROM your_table WHERE REGEXP_LIKE(yourlike_column,'ABC1')

for older Versions like 5.7

select "SomeString ABC1000 Other" REGEXP 'ABC1'
"SomeString ABC1000 Other" REGEXP 'ABC1'
1

fiddle

so the query would look like

SELECT yourcolmuns FROM your_table WHERE yourlike_column REGEXP 'ABC1'

Upvotes: 1

Related Questions