Skip site navigation (1) Skip section navigation (2)

Re: Help with a query

From: Erwin Van de Velde <erwin(dot)vandevelde(at)ua(dot)ac(dot)be>
To: Alexander Cohen <alex(at)toomuchspace(dot)com>,pgsql-general(at)postgresql(dot)org
Subject: Re: Help with a query
Date: 2004-02-26 22:08:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general

Without further information, this is rather difficult, but assuming that you 
have a table with userdata with a primary key UID and a unique UserName, and 
that you have a table of usergroups with a primary key GID and unique 
GroupName, the best way is to make a third table Users_Usergroups e.g.
where you put the couples (UIDX, GIDX) for a user with UID=UIDX and who is in 
group GIDX.
The query would then be:
SELECT GroupName FROM Users_Usergroups JOIN Users ON Users.UID = 
Users_Usergroups.UID JOIN Usergroups ON Usergroups.GID = Users_Usergroups.GID
WHERE UserName Like 'The User';

Erwin Van de Velde
Student of University of Antwerp

On Thursday 26 February 2004 22:47, Alexander Cohen wrote:
> Hi,
> Im trying to get a list of all groups that a certain user is a member
> of. Can anyone help me with the sql to get that?
> thanks!

In response to

pgsql-general by date

Next:From: Alex SatrapaDate: 2004-02-26 22:21:52
Subject: Re: postgreSQL licenseing
Previous:From: Alexander CohenDate: 2004-02-26 21:47:10
Subject: Help with a query

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group