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: How do i check if records exits in other tables?

Re: How do i check if records exits in other tables?

From: Daniel Morgan <dmorgan_at_exesolutions.com>
Date: Mon, 27 May 2002 15:31:45 GMT
Message-ID: <3CF2515B.8DFDF842@exesolutions.com>


K Allen wrote:

> I have a select statement by a single key that needs to check if that key or
> records with that key exist in another table, If they do fine, return
> 'yes' in a column, If they dont then return 'no'

This is not a wonderful bit of SQL but it will do the job.

SELECT a.field1, 'Yes'
FROM table1 a, table2 b
WHERE a.pk_field = b.pk_field
UNION
SELECT field1, 'No'
FROM table1
WHERE pk_field NOT IN (

   SELECT pk_field
   FROM table2);

I suspect a few seconds with DECODE and NOT EXISTS would yield a far more elegant result.

Daniel Morgan Received on Mon May 27 2002 - 10:31:45 CDT

Original text of this message

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