K
K
korvin22018-10-13 23:33:21
SQL
korvin2, 2018-10-13 23:33:21

How to get the string containing the tag?

There is a tag column separated by commas like "green, big, strong". I know this is not the best way to store tags, I'll change this later, but you need to run a query to find a row containing a specific tag right now. For example, in the first entry such tags are: "green, big, strong". In the second: "green , big, strong." When I use

"SELECT * FROM tablename WHERE tags LIKE '%зелен%'"

both records are returned (due to green ) , but only the first one is needed.
Perhaps you need to use not LIKE, but something else. Tried with IN but didn't work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
korvin2, 2018-10-14
@korvin2

This query works: select * from `table` where (tags LIKE '%tag,%' OR tags LIKE 'tag' OR tags LIKE '%, tag')

I
Ivan Shumov, 2018-10-14
@inoise

you can try regular expressions instead of LIKE but they are slow. better change the structure. it takes about 10 minutes, if the whole project has not yet spread

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question