A
A
Alexander Wolf2013-06-15 23:01:24
PHP
Alexander Wolf, 2013-06-15 23:01:24

Sampling by regular expression?

Hello! Please tell me: in my database table, the data is stored in this way:
id | name | items
1 | test | '0, 2, 3'
2 | test2 | '1, 4'
3 | test3 | '5'
And I need to make a selection ( `id` - int, `name` - varchar, `items` - varchar), for example, by the presence of the number 4 in items
. ВЫБРАТЬ `name` ГДЕ `items` СОДЕРЖИТ '4';must issue test2etc.
I apologize for such a chaotic question, but still.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Birzhakov, 2013-06-16
@mannaro

In this case, it is more convenient to make a linked ordered_items table, this will greatly untie your hands when developing the project.

L
larikov, 2013-06-15
@larikov

select name from your_table where find_in_set('4', items) > 0

R
raskumandrin, 2013-06-15
@raskumandrin

Add ", " at the beginning and end of the line, then use like:
select * from your_table where concat( ', ' , items , ', ' ) like ', 4, '

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question