S
S
shasoft2016-01-19 17:18:05
MySQL
shasoft, 2016-01-19 17:18:05

Select rows by string field with partial match?

There is a table with a text field ' path ' for example with the following values:

/aaa/bbb/ccc/1
/aaa/bbb/xxx/2
/aaa/zzz/
/aaa/zzz/ccc/
/aaa/bbb/ccc/3
Selecting by value ' /aaa/zzz/ccc/aaa ' should select string ' /aaa/zzz/ccc/ ',
selecting by value ' /aaa/zzz/cc ' should select value ' /aaa/zzz/ '
T .e. each time the value
1 should be selected. The length of which is less than or equal to the length of the desired value
2. The length of the match of which (from the beginning of the value) is maximum
Can you suggest a query or at least in which direction to look?
It is clear that you can enter the field length and select the condition according to paragraph 1 according to it. But I have problems with the second paragraph.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2016-01-20
@shasoft

Remove the upper entities one at a time and search until something is found.

S
shasoft, 2016-01-19
@shasoft

There was an idea with the function LEFT('search string', `field with a long string value`).
You only need to find out whether it is possible to substitute a table field into the function, i.e. will it work.

N
nozzy, 2016-01-19
@nozzy

select 
t1.path
from
your_table t1
where 
locate(t1.path, '/aaa/zzz/ccc/aaa')>0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question