mysql - Can this be done in a single SQL query? -
i have table lists columns list_id, name, etc. have table members columns user_id , list_id (with unique index on pair (user,list)).
now, want generate three-column output: list_id, name, membership membership 0 or 1 depending on whether or not current user member of list (i.e. there entry user on list). if
select list_id, name, 1 lists left join members on (lists.list_id = members.list_id , members.user_id=2) i correct 1-rows user 2, 0-rows gone. there nice way obtain desired effect single mysql query?
i think want this:
select list_id, name, (m.list_id not null) memberonlist lists l left join members m on l.list_id = m.list_id , m.member_id = @currentuser;
Comments
Post a Comment