Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Multi-query simplification
The only way I can think of is to UNION all selects together and make sure that the results come out in the correct order (in case you get a result from query 3 as well as from query 1 say) and then simply extract the first record.
try something like
select 1, data from table
where a and b and c and d
union
select 2, data from table
where a anb b and c
union
select 3, data from table
where a and b and d
union
select 4, data from table
where and b
order by 1
This will give you the resault from each query in turn. Simply take the first record.
Sorry I can't think of a better idea at the moment. You still need all four selects this way.
Alan
Mike Bongiovi <mbongiov_at_neuraltech.com> wrote in article
<688lti$c4f$1_at_news1.mnsinc.com>...
> I am querying records containing information about credit card
transactions,
> and I only want to find *one* record with this query and no more.
Criteria A
> is the customer's credit card number and criteria B is a reference number
given
> to the transaction which is not necessarily unique. Criteria C is the
date of
> the transaction and criteria D is the dollar amount of the transaction.
>
> The first level query would look like this:
>
> SELECT data FROM table
> WHERE A AND B AND C AND D;
>
> If nothing is found with this query, I must then do:
>
> SELECT data FROM table
> WHERE A AND B AND C;
>
> If nothing is found with this query, I must then do:
>
> SELECT data FROM table
> WHERE A AND B AND D;
>
> Finally, if nothing is found with this query, I must then do:
>
> SELECT data FROM table
> WHERE A AND B;
>
> In general, the query that ultimately is successful will find only one
> record. I only *want* one record, which is why I don't just start with
the
> last query. I was wondering if there was some way to simplify this
process.
> Remember, I'm looking for precisely one record.
>
> Thanks,
>
> Michael Bongiovi
> NeuralTech, Inc.
> Fairfax, VA
>
>
>
Received on Wed Dec 31 1997 - 00:00:00 CST
![]() |
![]() |