0
votes

I have a database of books. There is a Tag field that contains multiple tags and the number of tags isn't the same. So we have something like that in two rows:

comics,history

art,science,tag3,tag4

Now I have a string like $stringtosearch which can be any combinations of tags with that structure.

tag1,tag2... (it is with comma and I don't know the number of tags or commas...).

So how should I write the select query for that search?

NOTE: I want for example if user searches a string that contains 2 tags ,display records which has all two tags and not only one of them

1
Simple. See normalisation. - Strawberry
how many rows of this stuff shall I nicely call it at this point ? How many is So many :< - Drew
@drew Pierce So many rows - David Peterson

1 Answers

0
votes

You can use the Like keyword here.

SELECT * from tst where tags like '%t1%' AND tags like '%t2';

SQL Fiddle :- http://sqlfiddle.com/#!9/a3e6c/2