MySQL Query: Filtering search results by tags -
suppose have database table works link between 2 others. in case, link between book , tag, such "fiction" or "gardening". if have following dataset:
book_id | tag_id ---------------- 1 | 13 1 | 43 1 | 15 2 | 13 2 | 25
what kind of query run "find books have links tags 13, 43, , 15"? is, more tags add, smaller number of books shown.
i hope makes sense. in advance time , help!!
try this
select book_id book_tags group book_id having sum( case when tag_id in (13, 43, 15) 1 end ) >= 3
you need books have tags 13, 43, 15
(all of them), returns book_id = 1
result. sum() >= 3
specifies total number of tags searching, in case 3
, i.e 13, 43, 15
Comments
Post a Comment