Question : finding similarity

I have two tables like :

CREATE TABLE `content` (
`content_id` int(11) NOT NULL auto_increment,
`description` int(11) NOT NULL,
)

CREATE TABLE `content_favorites` (
`favorite_id` int(11) NOT NULL auto_increment,
`content_id` int(11) NOT NULL,
`members` int(11) NOT NULL,
)


I'm setting up like a system as users can add to contents(songs) to their favorites and contents linked with some of other contents.

So, There is a question like a splinter in my mind and I'm wondering how I can resolve that.

I've set up content and content_favorites tables. my next target is finding "user similarity".

I mean :
A user has 1,3,6,9 content_id in his content_favorites,
B user has 6,3,16,73 content_id in his content_favorites,
C user has 1,42,584,786 content_id in his content_favorites,

(simply it's looking A and B user has 50% similarity, A and C user has 25% similarity)

how can I find A and B, A and C user's similarity ratio and how can I get results order by ratio?

do you suggest create a new table like :

CREATE TABLE `content_link` (
`members_id` int(10) unsigned NOT NULL,
`content_id` text(10) unsigned NOT NULL default '0',
)

in this way, "content_id" column holds all content_ids of user's :
members_id : 2
content_id : 1,3,6,9 (or it can be hold via serialize method)

afterwards, I should use MATCH AGAINST query for finding similarity

OR

content_favorites table is enough for this query?

Answer : finding similarity

In that case you have to do a left join from members to users. Left means that all result of that table are show even if there are no results in the other one.

I hope that works, I never did a left join on a table out of a select. But there will be alternatives if not.
1:
2:
3:
4:
5:
6:
7:
8:
9:
select favorite_count_per_member.members, (favorite_count / (select count(*) from content_favorites where members = )) as ratio, members.*
from members left join ( select members, count(*) as favorite_count
       from content_favorites
       where content_id in (
                             select content_id from content_favorites
                             where members =  
                           )
group by members) as favorite_count_per_member on (favorite_count_per_member.members = members.members_id)
order by ratio desc
Open in New Window Select All
Random Solutions  
 
programming4us programming4us