The selection of records from the database according to the list of labels defined in another table?

0 like 0 dislike
In MySQL there is a table with records, also in a separate table are the "record id" — "id tag" that indicate which tags have marked the entry.

You need to select the records according to the user defined tags. While the tags in the query can be several and in this case, it selects all records that contain at least one of the following in the query tags.

A variant in which for each label creates a separate field in the table record is not suitable, because if necessary you want to add a new label without the code changes the sql query.

Could you tell me what sql query to do this sample?
by | 52 views

3 Answers

0 like 0 dislike
select the Entry from Tabletsaccutane where idЗаписи in (select idЗаписи from Tablecategories where idТега = 'correct tag')
0 like 0 dislike
SELECT r.* FROM Records r Record_Tag INNER JOIN rt ON rt.record_id = INNER JOIN Tag t ON = rt.tag_id WHERE IN ('tag1','tag2','tag3,...,'tagN') 

Will select all records (not unique) tag to walrath unique need to add DISTINCT or group, depending on how you intend to use the data.
0 like 0 dislike
You want in the final table of each tag was a separate field? Or a separate entry?

Related questions

110,608 questions
257,186 answers
32,912 users