Search code examples
mysqlin-operator

mysql cant add wildcard in IN Operator


I am trying to execute the following MYSQL QUERY, and it gives me an error, any ideas?

SELECT * FROM `cdr` WHERE `src` IN (5%,9725%,05%);

TIA


Solution

  • Your query doesn't work because your '%' is being interpreted as the modulo operator which is a binary operator and as such makes your syntax invalid.

     SELECT * FROM `cdr` WHERE `src` like '5%' OR src LIKE '9725%' OR src LIKE '05%';
    

    If you want to use the '%' character as a wild card it has to be quoted and used with the LIKE operator.