Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Complicated query: searching for results within results.

Re: Complicated query: searching for results within results.

From: Thorsten Kettner <thorsten.kettner_at_web.de>
Date: 20 Nov 2006 02:48:33 -0800
Message-ID: <1164019713.865003.254410@k70g2000cwa.googlegroups.com>


That is very easy. You want to know if the number of distinct Bs is the same as of distinct B/C combinations:

select case when count(distinct B) <> count(distinct B||'-'||C) then 'true' else 'false' end
from MyTable
where A = :GivenA

PS: I understand Daniel's remark not to solve student's tasks, but there is no way for us to determine, if the poster is a student or not. So I prefer to give a good answer that not only solves the problem, but also explains how to get to the solution for the learning effect. In this particular case however, the solution is so simple that you either find it immediately or you sit there for hours and hours, becuase the idea doesn't come to your mind. There is not much to learn.



phreaker wrote:
> Table 1 has columns A, B, and C
>
> For a given A, I need to figure out whether there exists <B,C> pairs
> that have the same B, but different C. For a given A, there are a
> potentially many Bs and many Cs.
>
>
> So for a given A, if there are these results in the table:
>
> B C
> 1 5
> 1 100
> 2 4
> 2 4
>
> I need to return true, since <1,5> and <1,100> have same B, but
> different C.
>
> Thanks!
> David
Received on Mon Nov 20 2006 - 04:48:33 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US