I have a search query which dynamically adds the search parameter LIKE “%keyword%” to the query. My question is: is the order of the search parameter important?
Say I have 4 records in my database.
1. 2012 bmw 335,
2. 2013 bmw x3,
3. 2012 audi a4,
4. 2012 Benz clk
When I searched for 2012 bmw x3, the result returned record 1,3,and 4 but not record 2. I would except the search to return all 4 records. Why is this happening? I use “OR” to link each of the search parameter.
Here is my query:
SELECT *
FROM for_sale
WHERE message LIKE "%2012%" OR "%bmw%" OR "%x3%"
This is what you’re after – remember that OR doesn’t bind to LIKE possibilities!