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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: SQL question

Re: SQL question

From: Jared Still <jkstill_at_gmail.com>
Date: Tue, 17 Jan 2006 09:42:02 -0800
Message-ID: <bf46380601170942l51b48c44sbc68b6a412199187@mail.gmail.com>


Try this:

select *
from foo
where item in (

   select item
   from foo
   group by item
   having count(*) = 2
)
and part in ('A','B')

Jared

On 1/13/06, Sandeep Dubey <dubey.sandeep_at_gmail.com> wrote:
>
> Hi,
>
> I am having tough time writing a select query. I won't blame it on
> Friday afternoon, it is really difficult to me.
>
> Here is an example:
>
> create table foo ( item number, part varchar2(2));
>
> insert into foo values(1,'A');
> insert into foo values(2,'A');
> insert into foo values(2,'B');
> insert into foo values(3,'A');
> insert into foo values(3,'B');
> insert into foo values(3,'C');
>
> I want to query for item that matches exact parts given in the query.
> i.e.if I query for part A, I should get 1 ( no 2 and 3)
>
> If I pass A and B , I should get only 2 (no 3)
> If I query for A, B and C, I should get only 3.
>
> Query can have n number of parts, It should return only that item that
> has exact match to parts, no less no more.
>
> Thanks
>
>
> Sandeep
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>

--
Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Jan 17 2006 - 11:56:32 CST

Original text of this message

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