mysql - Get related posts by tags -


hi i'm bad @ writing mysql queries (i'm working on it).

could guys me one?

i have table of tags:

id | tag -------------------------------- 1  | css 2  | c++ 3  | perl 4  | sql 5  | pyhton 

another table of postsa_tags:

id | postid | tag -------------------------------- 1  | 1      | 1 2  | 1      | 2 3  | 2      | 1 4  | 2      | 3 5  | 3      | 3 

another table of postsb_tags:

id | postid | tag -------------------------------- 1  | 1      | 2 2  | 2      | 3 3  | 2      | 1 4  | 3      | 4 5  | 3      | 5 

another table of posta:

postid | info -------------------------------- 1      | 2      | 2      | infor 3      | mation 4      | lol 

another table of postb:

postid | info -------------------------------- 1      | more 2      | infor 3      | mation 4      | please 5      | hahaha 

so now, challenge order b posts posts.

this means if peter owner of posts, need tags posts. in case be:

css, c++, perl 

while, sam owner of b posts. need order sam's posts (b posts), amount of coincidences between peter's tags (a tags) , tags each sam's post.

in case be:

b posts ordered coincided factor desc

postid | info -------------------------------- 2      | infor  1      | more 3      | mation 4      | please 5      | hahaha 

i'm stuck. know how sam's tags. not how measure coincidence factor between sam's tags , tags each peter's post.

sorry english :s

thanks in advance

here's fiddle... sqlfiddle.com/#!2/8450c/3

i think have resolved problem.

here query

select *, sum(`postsa_tags`.`tag` = `postsb_tags`.`tag`) rel `postsb_tags` left outer join `postsa_tags` `postsa_tags` on(`postsa_tags`.`tag` = `postsb_tags`.`tag`) group `postsb_tags`.`postid` order rel desc 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -