V
V
vitovt2014-02-28 11:49:49
SQL
vitovt, 2014-02-28 11:49:49

How to write a SQL query to search for text?

Actually there is a tags field, and it contains tags separated by commas. That is
, a word, a word, two words, some other tag, there may be a whole expression,
The search query consists of a word, but in the field this tag can be both at the beginning and at the end, it can be separated by commas on both sides or with one, maybe a comma and a space, then a word and a comma at the end, and so on. But it is important that by entering the query "word" there are only those who have a "word" but such tags as "the second word, the third word, another word," do not fall under the criterion.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2014-02-28
@kaasius

It is done like this.
1. A tag table is created. There is only id and tag.
2. For each tagged entity, a relationship table is created. The entity id and the tag id are stored there. How many tags an entity has, so many records in the relationship table with the id of this entity.
And accordingly, the search for tags is then performed as an exact match search.
Also, the way you are doing, you can implement it on Mongo for example.

A
Alexander Khirenko, 2014-02-28
@Satanpit

As I wrote here, you can try this:
but in general, yes, @kaasius says it all, if you have the opportunity to remake the structure - remake it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question