Simplify query select

Hello everyone, I need your help.

You can simplify this query in MySQL?


SELECT * FROM _tbl
   where 
     uo like '%M2%'
  or uo like '%M4%'
  or uo like '%M7%'
  or uo like ......
  or uo like ......

Thanks in advance-

no, sorry

:slight_smile:

Do you have something personal against me? :shifty:

No, his point is that query cannot be simplified. It’s not like when you’re seaching for distinct values and you can use the IN operator.

Using the LIKE forces each comparison to be done individually.

How can we simplify a query, when you don’t give us the full query to begin with?

From the looks of it, no is the answer.

Full query ?


SELECT * FROM _tbl
   where 
     uo like '%M2%'
  or uo like '%M4%'
  or uo like '%M6%'
  or uo like '%M7%'
  or uo like '%I1%'
  or uo like '%I5%'
  or uo like '%I6%'
  or uo like '%S1%'

Ok, then i point to Dave’s reply

oh, wait, i think you could also do this …


WHERE uo REGEXP 'M2|M4|M6|M7|I1|I5|I6|S1'

but it will be just as inefficient as the LIKE solution

Thanks for your help. :slight_smile: