You have a many-to-many relationship. Make three tables: sentence
, tag
and sentence_tag
. The sentence
and tag
tables will each have a primary key id
field and sentence_tag
will have a sentence_id
field and a tag_id
field. To find the tags for a sentence with id = $sID
,
SELECT tag_name FROM tags WHERE id IN (SELECT tag_id FROM sentence_tag WHERE sentence_id = $sID);