| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL for
If there are more posible values of foo, you can use a where:
"select bar from foobar
where foo between 1 and 3
group by bar
having count(distinct(foo)) > 2;"
Edorta wrote:
> I think this select does the work:
>
> "select bar from foobar
> group by bar
> having count(distinct(foo)) > 2;"
>
> Hope this helps,
> Edorta
>
> danielsomerfield_at_my-deja.com wrote:
>
> > Hello, I was wondering if someone could help me with a query. I have
> > found a long, rather convoluted inefficient way to do it and I am
> > wondering if there is a better one. If I have a table like so:
> >   foobar
> > foo | bar
> >     |
> > ---------
> > 1   |  a
> > 1   |  b
> > 1   |  c
> > 2   |  a
> > 3   |  a
> > 3   |  b
> >
> > I wish to get all the "bar"s which have "foo"s of 1, 2 and 3. So the
> > answer above is "a". The query I came up with is:
> >
> >         SELECT bar FROM foobar WHERE foo = 1
> >                 INTERSECT
> >         SELECT bar FROM foobar WHERE foo = 2
> >                 INTERSECT
> >         SELECT bar FROM foobar WHERE foo = 3;
> >
> > Ugly and cumbersome. What do you think? Is there something a bit more
> > elegant?
> >
> > Dan
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
Received on Fri Nov 19 1999 - 03:53:21 CST
![]()  | 
![]()  |