The original query looks like this (MySQL):
SELECT * FROM books WHERE title LIKE '%text%' OR description LIKE '%text%' ORDER BY date
Would it be possible to rewrite it (without unions or procedures), so that result will look like this:
- list of books where title matches query ordered by date, followed by:
- list of books where description matches query ordered by date
So basically just give a higher priority to matching titles over descriptions.
In sql server I would do the following:
I’m not sure if you can include columns in ORDER BY in mysql that aren’t in the SELECT, but that’s the principle I’d use. Otherwise, just include the derived column in the SELECT as well.