M
M
Max Payne2018-09-09 18:54:06
MySQL
Max Payne, 2018-09-09 18:54:06

Sorting output by index in string?

Let's say I have a query like

SELECT command_name, command_class_name, command_args 
FROM commands 
WHERE 'тир {DIALOG} погода 1' LIKE CONCAT('%', command_name, '%');

And the result is like
{DIALOG} *** ***
погода *** ***
тир *** ***

It is clear that the database sorts them according to the principle "higher is the position of the result, the row of which is earlier in the table".
How to sort them according to the principle "higher is the position of the result that is earlier in the search string"?
LOCATE() / INSTR()
Is it worth it to do this using MySQL, or is it better to sort using the programming language?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Payne, 2018-09-10
@YardalGedal

How to sort them according to the principle "higher is the position of the result that is earlier in the search string"?
Use LOCATE() / INSTR()
Question updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question