use sql to expand list of principal IDs into a list of the component user IDs?

LabKey Support Forum (Inactive)
use sql to expand list of principal IDs into a list of the component user IDs? Ben Bimber  2011-09-22 13:20
Status: Closed
 
I have a table that stores a list of the people who 'subscribe' to certain events. this table has 2 columns: eventName and principalId. The latter is either a userId or a groupId. I'd like to issue a query through the API that takes my list and expands the groups to find all the distinct users subscribing to a given event. the following works, but for my own edification is there a more elegant method to do what i'm trying? not that this is that hard, but it seemed like it ought to be possible in a single query.

--first find groups
select
n.notificationtype,
n.recipient,
m.Userid,
from ehr.notificationrecipients n
left join core.members m on (n.recipient = m.GroupId)
where m.userid is not null

union all

--then union to users
select
n.notificationtype,
n.recipient,
u.UserId,
from ehr.notificationrecipients n
left join core.users u on (n.recipient = u.userid)
where u.userid is not null

thanks.
 
 
jeckels responded:  2011-09-22 17:32
Hi Ben,

I think that's the best way to do it through what's exposed through the public queries. The ISMEMBEROF() function always operates on the current user, so it won't help in your scenario.

Thanks,
Josh