Sort by greater coincidence SQL?

Hi all.

The problem is how to make sorting by more coincidence, like sql ?

select * from table where like '%name%' order by (like '%name') ?


Or as, prompt please, such things hunker down..
June 14th 19 at 20:26
1 answer
June 14th 19 at 20:28
Solution
A criterion like '%name' - a qualitative, not quantitative, returns true/false.
I think you wanted something else, but you yourself can tell you about them?

DROP TABLE IF EXISTS tmp;
CREATE TABLE tmp (
 `id` INT PRIMARY KEY,
 `name` VARCHAR(50)
)
 DEFAULT CHARSET = utf8;

INSERT INTO tmp (`id`, `name`)
VALUES (1, 'Pumping equipment'), (2, 'blah-blah'), 
 (3, 'Pump'), (4, 'spare parts for the pump');

SELECT *
FROM tmp
WHERE `name` REGEXP '[NN]ASOs[[:>:]]'
UNION
SELECT *
FROM tmp
WHERE `name` REGEXP '[NN]ASOs';
not quite understand
there is a request

Select *** where `name` like '%name%' or `keys` like '%name' order by `name`

How to bring first results with the highest match, please tell me - Carli.Harr commented on June 14th 19 at 20:31
I repeat slowly:
The like operator '%name' returns true/false, it does not give grades.
Before answering, I would like to clarify what "largest match" and that match is smaller.
Before you answer, think. This might help. - Benedict_Shiel commented on June 14th 19 at 20:34
did everything using match against, but the result will appear chaotic, still can't understand how to display item with great coincidence above others

For example there is the string "Pump", "Pumping equipment", "parts for pump", do a search for "pump"
You will find all 3 rows, but how do I output 1 line above the rest? because it coincides more with the search word

Please tell me that the noob in sql - Carli.Harr commented on June 14th 19 at 20:37
it coincides more with the search word

who told you such nonsense? he came up with? all 3 lines equally match the condition of the sample. you own something made up, and now complain that SQL does not work as you come up with. - Jensen.Stros commented on June 14th 19 at 20:40
how then to solve the problem, force MB php ? - Carli.Harr commented on June 14th 19 at 20:43
and what if "pump 1, pump 2, pump 3"
I have all 3 displays to search for "pump 1"
don't understand what's going on) - Carli.Harr commented on June 14th 19 at 20:46
look in response. - Benedict_Shiel commented on June 14th 19 at 20:49
thank you very much) - Carli.Harr commented on June 14th 19 at 20:52

Find more questions by tags SQLMySQL