Let's have a simple InnoDB table questions
containing one column text
, which contains following data:
What color does the sun have?
What year it is?
What year was Barack Obama born?
Where in europe people speak french?
When stackoverflow started?
Now, I would like to search through this column:
SELECT *
FROM `questions`
WHERE `text` LIKE '%What%' OR `text` LIKE '%year%';
However this generate output:
What color does the sun have?
What year it is?
What year was Barack Obama born?
I would like the output ordered by the occurence of searched words. In another words when question contains both "What" and "year" it should precedes questions that contain "What" only. So the output would look like this:
What year it is?
What year was Barack Obama born?
What color does the sun have?
Can that be done using MySQL only? If not is there a nice way of doing this using PHP?