Kai Peters <[email protected]> wrote:
> the query below (ready to paste & run in the editor of your choice) works but
> I have a strong
> suspicion that it might be optimizable:
>
> select SUG.UserGrpID, SUG.GroupName, SUM.A_Link, SUM.B_Link
> from SecUserGroups SUG
> left outer join SecUserMembers SUM on SUM.UserGrpID = SUG.UserGrpID
> where SUM.UserID = 'Jane Doe'
> union
> select SUG.UserGrpID, SUG.GroupName, 0, 0
> from SecUserGroups SUG
> where UserGrpID not in (select UserGrpID from SecUserMembers where
> UserID = 'Jane Doe')
select SUG.UserGrpID, SUG.GroupName,
coalesce(SUM.A_Link, 0), coalesce(SUM.B_Link, 0)
from SecUserGroups SUG left outer join SecUserMembers SUM
on (SUM.UserGrpID = SUG.UserGrpID and SUM.UserID = 'Jane Doe');
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users