skip to Main Content

I need to fetch the string For reference

110_112_120_122_130_132_140_143_149_151_154_160_162_165_171_173_194_215_236_257_278_299

use this as a subjects

I am using the below query

select * from table_name where subjects like '%_21_%' ;

which is not showing desired result.

Note – 21 can come anywhere in the string in start 21_ or middle 21 or tail _21

2

Answers


  1. _ is a special character while using like and means exect one character, you have to escape it:

    select * from table_name where   subjects like '%_21_%' ;
    

    For more information see https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like

    Login or Signup to reply.
  2. select * from table_name where  subjects like '%_299_%' 
    or subjects like '%299_%' or 
    subjects like '%_299%';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search