I am currently performing a search function. Suppose my database has the following data:
- Keyword 1
- word 2
- KEYWORD3
- Keysomething
- Key
and the user entered: "Key" as a search keyword. This is my current request:
SELECT * FROM data WHERE (
data_string LIKE '$key%' OR
data_string LIKE '%$key%' OR
data_string LIKE '%$key'
)
Basically, I have 2 questions:
How to sort (in order) similarity. From the above example, I wanted Key to be my first result. My current result: keyword1, keyword2, keyword3, keyword and key
My SQL query only searches the column "data_string", what if I want to see other columns? I need to do something like this:
SELECT * FROM data WHERE (
data_string LIKE '$key%' OR
data_string LIKE '%$key%' OR
data_string LIKE '%$key'
) OR (
data_other LIKE '$key%' OR
data_other LIKE '%$key%' OR
data_other LIKE '%$key'
)
Is there a better / faster request than Q2?