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

Home -> Community -> Usenet -> c.d.o.server -> Re: Tricky query?

Re: Tricky query?

From: Sybrand Bakker <gooiditweg_at_sybrandb.verwijderdit.demon.nl>
Date: Fri, 27 Aug 2004 00:03:21 +0200
Message-ID: <bansi0lscmjrfqbq4nmublov0flkav4rc4@4ax.com>


On 26 Aug 2004 13:32:09 -0700, ibm_97_at_yahoo.com (JZ) wrote:

>Hi,
>
>Oracle 9205
>
>I have a table:
>
>SQL> select * from ASSETGROUPSMAPPINGS;
>
>ASSETGROUPID ASSETID
>------------ ----------
> 1 1
> 1 3
> 1 4
> 1 6
> 2 3
> 2 5
>
>
>Now I like to have a query which can return a common 'assetgroupid'
>for a list of 'assetid'. I know it can be done through 'intersect':
>
>SQL> select unique ASSETGROUPID from ASSETGROUPSMAPPINGS where ASSETID
>=3 intersect select unique ASSETGROUPID from ASSETGROUPSMAPPINGS where
>ASSETID =5;
>
>ASSETGROUPID
>------------
> 2
>
>
>The problem is that the number of 'assetid' is not fixed, it could be
>2, 3, or 6. So it's difficult to implement into our JAVA code.
>
>Any ideas?
>
>Thanks a lot!

The 2 unique keywords are redundant. The result of intersect is a set and set consists by definition of unique elements. The select can be written as
select distinct assetgroupid from assetgroupmapping where assetid in (3,5)

and it is a bit strange you think you need intersect. The second remark is even more strange. Why would it be difficult to implement?

--
Sybrand Bakker, Senior Oracle DBA
Received on Thu Aug 26 2004 - 17:03:21 CDT

Original text of this message

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