skip to Main Content

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"

2

Answers


  1. Chosen as BEST ANSWER

    Found answer with LIKE

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

    Thank you!


  2. 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'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search