Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Quick nested SQL question
"Rich" <richmun_at_yahoo.com> wrote in message
news:ZO7B9.9383$%m4.2326_at_rwcrnsc52.ops.asp.att.net...
> Howdy. Ok it's an ugly SQL statement. But I wonder if it should work?
>
> I have a user table t_user, and a group of friends (of the users) table
> t_group.
>
> Looks like this
>
> T_USER
>
> ID FIRSTNAME ...............................
> ----------------------------------------------------------
> 409 RICH
> 500 JIM
> 600 BOB
> 700 TOM
>
> T_GROUP
>
> ID FRIEND_ID ...............................
> ----------------------------------------------------------
> 409 500
> 409 600
>
> I want to be able to select records in t_user for RICH but exclude RICH's
> FREND_ID's (He's already added them so I don't want to give him a choice
on
> the GUI.
>
> Or is there a better way to execute this?
>
> Here is my first shot at it.
>
> select t_user.id , t_user.firstname, t_user.lastname from t_user,
t_group -
> where (t_group.friend_id) in -
> ( -
> select t_group.friend_id from t_group where (t_group.friend_id) NOT
> IN -
> ( -
> select t_group.friend_id from t_group where t_group.id = '406' -
> ) -
> );
Very ugly statement...
Why you doing no join between t_group and t_user?
It'll produce cartesian product for you:
each record in t_user will be repeated for the each record selected from
t_croups.
Pls describe how rely t_group on t_user.
>
> Any help would be appreciated. Thanks
>
> rich
>
>
>
>
Received on Wed Nov 20 2002 - 07:59:27 CST
![]() |
![]() |