Mysql select command combines one and more

the best way to make this request

SELECT * FROM `table` WHERE  `column` like '%abc% %xcdb%' OR  `column` like '%abc% %dfhj%'

      

Here the first variable stays the same, but the second changes as it allows you to specify an array from 10 to 20 So the best and quickest way to iterate over this iterative ( column

like)

table design

<table >
<tr>
    <td>id</td>
    <td>column</td>
    <td>other</td>
</tr>
<tr>
    <td>1;</td>
    <td>fsyd,**abc**,jgd,**xcdb**,sdfr</td>
    <td>tom</td>
</tr>
<tr>
    <td>2</td>
    <td>wer,tyuy,dhjd,dbhd</td>
    <td>john</td>
</tr>
<tr>
    <td>3;</td>
    <td>asy,gtyt,bnhhs,**abc**,bgy,trdcv,**dfhj**</td>
    <td>colin</td>
</tr>
     <tr>
    <td>4</td>
    <td>wer,**xcdb**,dhjd,**abc**,dbhd</td>
    <td>john</td>
</tr>
</table>     

      

this query returns the result id (1 and 3), but not 4 as it is checking the sequence. this is the correct select operator and returns the result I want, but I'm only asking for a better way to do this.

+3


source to share


1 answer


Based on what you are asking and the implications of that order, you have two options:

  • Quoting across a bunch of LIKE

    requests (how do you do it)
  • REGEX's

As far as I understand, there is significant success for regex in MySQL, but I cannot verify this firsthand. I'll try and post an example of your request using regex if that's what you want, and I have a few minutes to test.



It should look something like this:

SELECT * FROM `table` WHERE  `column` REGEXP('.*abc.*((xcdb)|(dfhj).*)')

      

See proof in SQLFiddle here: http://sqlfiddle.com/#!2/8cd26/1

0


source







All Articles