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: Union Query Improvement

Re: Union Query Improvement

From: Ed Prochak <edprochak_at_gmail.com>
Date: 14 Feb 2007 07:39:25 -0800
Message-ID: <1171467564.934533.57040@h3g2000cwc.googlegroups.com>


On Feb 14, 9:59 am, "Ray Bannon" <raymond.w.ban..._at_boeing.com> wrote:
> Howdy, I've got a query which runs forever and am wondering if there's a
> more efficient way to write it.
>
> Select id, plan_name from table/view1 where plan_name = 'A' and rownum = 1
> union
> Select id, plan_name from table/view1 where plan_name = 'B' and rownum = 1
> union
> Select id, plan_name from table/view1 where plan_name = 'C' and rownum = 1
> union.....etc
>
> There are about 100 plan names, and I want one ID/owner for each plan_name.

wouldn't
SELECT DISTINCT id, plan_name from table/view1 ; work?
I dislike DISTINCT since many folks use it for the wrong reasons, but this seems a perfect place for it.

Ed Received on Wed Feb 14 2007 - 09:39:25 CST

Original text of this message

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