0

So it's just a simple question I have this query. It's not working so I just thought I'd make sure that this isn't possible.

SELECT * FROM warehouse WHERE sku LIKE IN ($clean) AND style= :style9 ORDER BY sku ASC
Cœur
  • 37,241
  • 25
  • 195
  • 267
0cean_
  • 31
  • 1
  • 7

5 Answers5

1

I don't recognize LIKE IN as a thing.

You might try sku LIKE '%' + ($clean) + '%'

Or, if you're looking for it the other way around: ($clean) LIKE '%' + sku + '%'

Is there a combination of "LIKE" and "IN" in SQL? Here is a discussion of using Contains, if you would like to try using that.

Community
  • 1
  • 1
Coding Orange
  • 548
  • 4
  • 7
1
There is no combination of LIKE & IN in SQL,so you have to use sql like

SELECT * FROM warehouse WHERE sku LIKE '%$clean%' AND style= :style9 ORDER BY sku ASC
jay.jivani
  • 1,560
  • 1
  • 16
  • 33
0

Like and In both are different thing, you can easily understand from the below snippet of code, hopefully this will help you to remove your confusion :)

select 
    *
from
    emp
where
    name like @param +'%'

Select
   *
from
   emp where name in ('abc', 'xyz')  
nitin
  • 156
  • 2
  • 13
0

Not knowing what your $clean value looks like (or your sku values or expected results) I can only guess, but REGEXP, also known as RLIKE, might be useful here.

Say you're looking for SKU's like 'AB%', 'XY%', and 'FG%'. You can do that with RLIKE as follows:

SELECT * FROM warehouse WHERE sku RLIKE '^(AB|XY|FG)' AND ...
Ed Gibbs
  • 25,924
  • 4
  • 46
  • 69
0

You could use REGEXP to achieve what your trying to achieve, so you query will look like

SELECT * 
FROM warehouse 
WHERE sku REGEXP REPLACE($clean,',','|') AND style= :style9 
ORDER BY sku ASC

Going on the assumption that $clean is comma delimited list of values.

ccStars
  • 817
  • 2
  • 11
  • 34