select - MySQL Search matching multiple keywords -
looking posts matching 2 keywords (both, not 1 of them).
i guess reason why following mysql query returns no matches keywords matching "climate" , keywords matching "recycling" not same rows in t_keywords table. how proceed?
select t_posts.id, t_posts.title t_posts, t_keywords, t_posts_keywords t_posts.id = t_posts_keywords.id_post , t_keywords.id = t_posts_keywords.id_keyword , t_keywords.keyword = "climate" , t_keywords.keyword = "recycling" group t_posts.id
select t_posts.id, t_posts.title t_posts, t_keywords, t_posts_keywords t_posts.id = t_posts_keywords.id_post , t_keywords.id = t_posts_keywords.id_keyword , t_keywords.keyword in ('climate', 'recycling') group t_posts.id having count(t_keywords.id) = 2
you group post, need check given post has 2 rows in original data, 1 each keyword - having for. if have variable number of keywords match, "2" has variable too, replaced right count application.
Comments
Post a Comment