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


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
46 views
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 | 46 views

3 Answers

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

\r
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.
by
0 like 0 dislike
You want in the final table of each tag was a separate field? Or a separate entry?
by

Related questions

110,608 questions
257,186 answers
0 comments
28,070 users