Answer the question
In order to leave comments, you need to log in
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 '%имя') ?
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question