php - sql join problem -
i want select posts contain specific tag. i'm trying query:
select group_concat(t.tag_name) taglist posts p join posts_tags pt on p.post_id = pt.post_id join tags t on t.tag_id = pt.tag_id (p.post_private = 0) , t.tag_name = 'php' group p.post_id
problem is, query above, selects posts contain php
tag, doesn't select of other tags post may contain. without and t.tag_name = 'php'
part, select every tag post has, want able filter tag...
any ideas how this? i've tried many things, can't figure out...
sample data without and
statement:
|| *taglist* || || php,echo || || c++, cout ||
sample data and
statement:
|| *taglist* || || php ||
what want:
|| *taglist* || || php,echo ||
(the posts contain php tag only)
select p.post_id, group_concat(t.tag_name) taglist posts p /* these 2 joins list of tags */ inner join posts_tags pt on p.post_id = pt.post_id inner join tags t on pt.tag_id = t.tag_id /* these 2 joins guarantee 'php' tag included */ inner join posts_tags pt2 on p.post_id = pt2.post_id inner join tags t2 on pt2.tag_id = t2.tag_id , t2.tag_name = 'php' p.post_private = 0 group p.post_id
Comments
Post a Comment