MYSQL database query: suggest users to follow -
i'm looking implement suggestion function twitter's "who follow" in system allows users follow each other. keep track of these subscriptions table this:
create table `subscriptions` ( `id` int(10) unsigned not null auto_increment, `follower_id` int(10) unsigned not null, `following_id` int(10) unsigned not null, `enabled` tinyint(1) not null default '0', )
i'm trying list of users current user not following.
so far i've tried using queries such as:
select distinct u.id, u.name, s.follwer_id, s.enabled users u left join subscriptions s on u.id = s.follwer_id , s.enabled = 0 u.id != 2
this query ends giving me lots of nulls , irrelevant rows.
thanks in advance.
in query, users
table refers users being followed. want follower_id
set current user , following_id
match users (for left join
):
select u.id, u.name, s.follower_id, s.enabled users u left join subscriptions s on u.id = s.following_id , s.enabled = 0 , s.follower_id = 2 s.following_id null
do note last 2 columns null
, because looking users there no matching subscriptions
record.
Comments
Post a Comment