0

Query code:

SELECT *
FROM example
WHERE name LIKE '%test%'
OR SOUNDEX(name) LIKE 'T230%'
OR SOUNDEX(name) LIKE 'T23%'

I want to show first the results matched with WHERE name LIKE '%test%' and after SOUNDEX(name) LIKE 'T230%' and the lasts rows is the result of SOUNDEX(name) LIKE 'T23%'

Thank you for the attention.

Miguilim
  • 25
  • 2
  • 7

1 Answers1

0

You can use boolean expressions in order by. The "true" is treated as "1" and false as "0". So:

ORDER BY (name LIKE '%test%') DESC,
         (SOUNDEX(name) LIKE 'T23%') DESC,
         (SOUNDEX(name) LIKE 'T230%') DESC
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786