Reputation: 31
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
Upvotes: 0
Views: 189
Reputation: 815
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.
Upvotes: 0
Reputation: 26333
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 ...
Upvotes: 0
Reputation: 156
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')
Upvotes: 0
Reputation: 1574
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
Upvotes: 1
Reputation: 542
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.
Upvotes: 1