Re: problem in with clause: if table1 is empty select from table2

From: Urs Metzger <urs_at_ursmetzger.de>
Date: Sun, 30 Mar 2008 11:59:54 +0200
Message-ID: <fsno8f$j0o$1@online.de>


nova1427_at_gmail.com schrieb:
> Please help me to write query like this
>
> WITH table_not_empty AS
> (
> if (SELECT * FROM Table1) is not empty return it_self
> else return (SELECT * FROM Table2)
> )

WITH table_not_empty AS
(

    SELECT 'it_self' FROM Table1
     WHERE ROWNUM = 1
    UNION
    SELECT * FROM Table2
     WHERE NOT EXISTS(SELECT NULL FROM Table1) )

HtH, Urs Metzger Received on Sun Mar 30 2008 - 04:59:54 CDT

Original text of this message