0

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"

4
  • All strings from a single column, all strings from all the columns, or search every single table and every single column? Commented May 7, 2024 at 20:28
  • '%ABC1%'. Post query, please Commented May 7, 2024 at 20:29
  • So you require ABC1 to be at the beginning of a word? Use a regexp, with the [:<:] word beginning pattern. Commented May 7, 2024 at 20:37
  • LIKE can't do this. Commented May 7, 2024 at 20:37

2 Answers 2

1

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'
Sign up to request clarification or add additional context in comments.

2 Comments

I think your answer is right. But regexp_like is an Oracle function. And I am using Mysql. It gave error as FUNCTION mysql.regexp_like does not exist
this was introduced in MySQL 8.x but i added for 5.7, if you are older you should think about updating the version
0

Found answer with LIKE

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

Thank you!

1 Comment

Often people do something like concat(' ',conditions) like '% ABC1%'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.