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: Returning DISTINCT rows when SQL *DOES NOT* contain distinct!

Re: Returning DISTINCT rows when SQL *DOES NOT* contain distinct!

From: <fitzjarrell_at_cox.net>
Date: 11 May 2005 20:21:39 -0700
Message-ID: <1115868099.054661.307640@g47g2000cwa.googlegroups.com>

vista..._at_yahoo.com wrote:
> Hi,
>
> Is there any way to force the result set to behave as if the SQL
> contained DISTINCT directive, when the SQL DID NOT actually contain
the
> "distinct" keyword? I am looking for ideas, so please feel free to
> suggest different ways (stored procedures, views, etc etc).
>
> Here is the query in question:
>
> SELECT ID FROM TABLE_A
> WHERE (ID in (select id from TABLE_B where code like 'ABC%'
> and dates between to_date('01-JAN-2003') and to_date('31-MAR-2004')))
> AND (ID IN ('123', '456'))
>
> I get a result set which contains LOTS of multiple rows for the same
> object_id, etc.
>
> You might be asking the obvious: why don't I add "distinct" to the
SQL.
> Well, the SQL is coming from an automated too, which builds the SQL
> based on param you provide, and there is no way to force it to send
> "distinct" as part of SQL.
>
> This is what I have control over:
> 1. specify name of TABLE_A (so it could be a view)
> 2. field name of "ID" field
> 3. whatever else I want as part of WHERE clause
>
> thanks
> Mark

Then you had best create a view returning distinct rows. Nothing in a WHERE clause will help you; only DISTINCT or GROUP BY will return unique records.

David Fitzjarrell Received on Wed May 11 2005 - 22:21:39 CDT

Original text of this message

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