0

I'm trying to write a query with LIKE and = conditions:

Model.where("extract(day from month) = ? OR lower(name) LIKE ?",params[:filter], "%#{params[:filter]}%".downcase )

I get return for the month value but i don't get any return for the name value.

so how can i use 'LIKE' and 'EQUAL TO' together in one query?

[EDIT] : when i use only the like statement it works fine.

1
  • Did you check, if there are any records getting returned when you only apply like query? Commented Jul 19, 2022 at 8:26

1 Answer 1

0

We can definitely use like and equal to in the same query. Your query looks correct. Please check with hardcoded values to double check ex: Model.where("lower(name) LIKE ?", "%aManda%".downcase ) and then same for both conditions together.

Sign up to request clarification or add additional context in comments.

3 Comments

when i use only one LIKE or multiple LIKE with OR/AND it works the problem is when i mix LIKE and EQUAL at the same time
Can you share exact query which does not work to demonstrate "i mix LIKE and EQUAL at the same time" ?
Model.where("extract(day from month) = ? OR lower(name) LIKE ?",params[:filter], "%#{params[:filter]}%".downcase )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.