I’m having a bit of a conundrum here. I’m baking a recipe application and let’s say I have a query of “mayonnaise”, “bacon” and “cheese”.
I’d like to return all the recipes containing “mayonnaise” or “bacon” or “cheese” ordered by if they have “mayonnaise”, “bacon” AND “cheese” followed by those that just have “mayonnaise” AND “bacon”, etc.
So far I have something a bit cloogey like:
SELECT * FROM recipes
WHERE LOWER(ingredients) LIKE '%mayonnaise%'
OR LOWER(ingredients) LIKE '%bacon%'
But that’s just one half of what I want. How do I get across the finish line?
Thanks!
You could try prioritising the presence of ingredients and ordering by whether or not the ingredient is included: