Unix Technical Forum

Re: Need help with a complicate sql select request

This is a discussion on Re: Need help with a complicate sql select request within the Informix forums, part of the Database Server Software category; --> Thorsten Knopel wrote: > Sorry corrected value in Table B > > Thorsten Knopel wrote: > >> hello , ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 12:32 PM
Art S. Kagel
 
Posts: n/a
Default Re: Need help with a complicate sql select request

Thorsten Knopel wrote:
> Sorry corrected value in Table B
>
> Thorsten Knopel wrote:
>
>> hello , i need some help for a complicate sql search, hope someone can
>> help me
>>
>>
>> Problem:
>>
>> Table A: mega_grp, grp
>> ----------------------
>>
>> e.g. mg1, grp1
>> mg1, grp2
>> mg2, grp3
>> -----------------------
>>
>> Table B: user, grp
>> ----------------------
>> e.g. usr1, grp1
>> usr1, grp2
>> usr2, grp1
>> usr2, grp3
>> ----------------------
>>
>>
>> What we want is to find all user which are in mega_group "mg1". That
>> mean all user which are in "grp1" and "grp2". Not only in one but in
>> both. In the example it would be only "usr1" because "usr2" is not in
>> "grp2"


Note that 'user' is a poor choice for a column name since it is also a
built-in variable returning the user's login name. So it must be qualified
in queries with the tablename:

select mega_grp, b.user, count(*)
from tablea a
join tableb b
on a.mega_grp = 'mg1' and a.grp = b.grp
group by mega_grp, user
having count(*) > 1;

Just leave off the "a.mega_grp = 'mg1'" filter to find all users in any
mega-grp. This will work for mega-grps defined with 2 or more grps/

Art S. Kagel

>> I tried it with a subselect and an IN Operation but then i get all
>> user which are in one of the groups but not in both.
>>
>>
>> Thanxs for your help
>>
>> Thorsten




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com