J
J
jorshjorsh952017-10-03 09:40:56
MySQL
jorshjorsh95, 2017-10-03 09:40:56

Sorting by largest match SQL?

Hello.
The problem is how to make sorting by larger match like sql ?

select * from table where like '%имя%' order by (like '%имя') ?

Or how, please tell me, I got stuck on such a trifle ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2017-10-03
@jorshjorsh95

Criterion like '%имя'- qualitative, not quantitative, returns true/false.
It seems to me that you wanted something else, but you yourself can tell about it?

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, 'Насосное оборудование'), (2, 'бла-бла'), 
       (3, 'Насос'), (4, 'запчасти для насоса');

SELECT *
FROM tmp
WHERE `name` REGEXP '[Нн]асос'
UNION
SELECT *
FROM tmp
WHERE `name` REGEXP '[Нн]асос';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question