Mysql - search for blogs by tags -


i'm using following query search blogs contain words in titles. each word recorded unique in table tags , referenced actual blog in table tags_titles. t.label actual tag words stored.

for reason query not produce ay results, unless input number in case produces blogs without filtering. how can work?

select tt.blog_id, b.title, count(*) total_matches tags_titles tt  inner join tags t on tt.tag_id = t.tag_id  left join blogs b on tt.blog_id=b.blog_id  t.label in ('boats','planes') group tt.blog_id order total_matches desc 

i think want right join rather left join , fix other details in query:

select b.blog_id, b.title, count(t.label) total_matches tags_titles tt inner join      tags t      on tt.tag_id = t.tag_id right join      blogs b      on tt.blog_id=b.blog_id ,         t.label in ('boat','plane') group b.blog_id order total_matches desc; 

you asking @ blog level. however, join instead keeping tags, rather blogs. once switches blogs, total_matches counts number of matching tags count (count(*) never return 0 in case, because there no row).

if want @ least 1 match, include having total_matches > 0.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -