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

Home -> Community -> Usenet -> c.d.o.tools -> Re: help with a simple query

Re: help with a simple query

From: Marc Billiet <someone.overthere_at_living>
Date: Tue, 19 Dec 2000 06:40:05 GMT
Message-ID: <20001219.6400516@slu40xxx.hae.hydro.com>

You can try:

select a.*
from a, b
where ((a.col1 is not null and a.col1 = val1) or (a.col1 is null and b.col1 = val1))
and a.col2 = b.col2

or shorter:

select a.*
from a, b
where nvl(a.col1, b.col1) = val1
and a.col2 = b.col2

If table b can be empty, you can use :

select *
from a
where (a.col1 is not null and a.col1 = val1) or (a.col1 is null and exists(
  select 1
  from b
  where b.col2 = a.col2
  and b.col1 = val1)

or

select a.*
from a, b
where nvl(a.col1, b.col1) = val1
and a.col2 = b.col2(+)

Marc

>>>>>>>>>>>>>>>>>> Oorspronkelijk bericht <<<<<<<<<<<<<<<<<<

Op 2000-12-18, 22:47:26, schreef javadrink_at_my-deja.com over het thema

help with a simple query:

> I need to do a following query (using table a, b):

> select *
> from a
> where a.col1=val1 or if a.col1=null then b.col1=val1
> wherea.col2 = b.col2
 

> how to express the if part using SQL? thanks a lot!
 

> (basically what I want to do is: selection based tableA column1, but i
 f
> tableA column1 is null, join tableA with tableB using column2 and make
 

> sure tableB column 1 equal to the input value)
 

> Thanks!

> Sent via Deja.com
> http://www.deja.com/
Received on Tue Dec 19 2000 - 00:40:05 CST

Original text of this message

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