john john - 24 days ago 9
PHP Question

Query wildcard with IN

I have this query:

select * from orders where week_of_year = '40' and user_id = '8631' and charge_date like in ('2017%','2018%') order by id desc limit 1


I have a syntax error near charge_date, I know the error I'm guessing I can't use like with 'in', is there anyway I can do the same logic that would actually work?

Answer Source

I guess, you need only year from the date and you want to search for multiple possible years.

Then your solution should look like below:

select * from orders where week_of_year = '40' and user_id = '8631' and YEAR(charge_date) REGEXP '2017|2018' order by id desc limit 1