mertdaglaroglu
05-13-2009, 11:24 PM
I'm trying to make a query to get unique results and also eliminate some of them.
So I'm trying to make a system like last.fm structure.
members can add any content to their favorites (for example a song). and all songs can be linked by other songs. (A song linked by B song. like last.fm) Then if member add "A song" to his favorites, system suggest him "B song". but because off cross linking in database, results contain A and B song together. so system need to eliminate A song because of it's already in user's favorite.
My linked contents and favorites table same as following :
CREATE TABLE `content_link` (
`id` int(10) unsigned NOT NULL auto_increment,
`content_id` int(10) unsigned NOT NULL default '0',
`linked_id` int(10) unsigned NOT NULL default '0',
)
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 trying to use the line below to get results (in fact I tried many others but I couldnt achieve):
SELECT DISTINCT olink.content_id FROM content_link AS olink, content_favorites AS ofav WHERE ofav.content_id=olink.linked_id AND olove.members_id ='2'
Only that I need eliminate results which are same with "content_favorites"'s content_id. But I couldnt achieve this.(I tried inner, outer, right, left join combinations and my mind is outer joined now!)
I hope anyone has an idea on that
EDIT:
my tables content example like following :
CONTENT_LINK (I'm using cross linking for every linked items)
content_id :1 - linked_id : 3
content_id :3 - linked_id : 1
content_id :1 - linked_id : 5
content_id :5 - linked_id : 1
CONTENT_favorites
content_id :1 - members_id : 2
content_id :3 - members_id : 2
So I'm trying to make a system like last.fm structure.
members can add any content to their favorites (for example a song). and all songs can be linked by other songs. (A song linked by B song. like last.fm) Then if member add "A song" to his favorites, system suggest him "B song". but because off cross linking in database, results contain A and B song together. so system need to eliminate A song because of it's already in user's favorite.
My linked contents and favorites table same as following :
CREATE TABLE `content_link` (
`id` int(10) unsigned NOT NULL auto_increment,
`content_id` int(10) unsigned NOT NULL default '0',
`linked_id` int(10) unsigned NOT NULL default '0',
)
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 trying to use the line below to get results (in fact I tried many others but I couldnt achieve):
SELECT DISTINCT olink.content_id FROM content_link AS olink, content_favorites AS ofav WHERE ofav.content_id=olink.linked_id AND olove.members_id ='2'
Only that I need eliminate results which are same with "content_favorites"'s content_id. But I couldnt achieve this.(I tried inner, outer, right, left join combinations and my mind is outer joined now!)
I hope anyone has an idea on that
EDIT:
my tables content example like following :
CONTENT_LINK (I'm using cross linking for every linked items)
content_id :1 - linked_id : 3
content_id :3 - linked_id : 1
content_id :1 - linked_id : 5
content_id :5 - linked_id : 1
CONTENT_favorites
content_id :1 - members_id : 2
content_id :3 - members_id : 2