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: Query Help Needed

Re: Query Help Needed

From: Rob Fegan <l120bj_at_aol.com>
Date: 17 Feb 2001 17:12:01 GMT
Message-ID: <20010217121201.17786.00001429@ng-fk1.aol.com>

>Subject: Query Help Needed
>From: GZ gregz_at_yahoo.com
>Date: 2/17/01 2:13 PM GMT Standard Time
>Message-id: <3A8E8A62.79D1129A_at_yahoo.com>
>
>I would like to know how I can implement a if/then type logic when
>selecting from two tables in sub query?
>
>I want the outer query to:
>
>1. take departments from table A
>2. if the department exists in table A, do not take that same department
>from table B.
>3. take any department from table B that does not exist in table A.
>
>1st table in sub query brings up departments that have more than zero
>persons in it.
>
>2nd table in subquery brings up departments from another table and
>manufactures a zero for # of people.
>
>
>SELECT deptno, num_people
>FROM
>(SELECT deptno, num_people FROM tableA
>UNION ALL
>SELECT deptno, '000' as num_people FROM tableB)
>
>Any help would be immensely appreciated!
>
>GZ

Hi GZ,
  How about

SELECT deptno, sum(num_people)
FROM
(SELECT deptno, num_people FROM tableA
UNION
SELECT deptno, 0 as num_people FROM tableB) group by 1

  Not too much of a change from your query.

Regards,
  Rob Received on Sat Feb 17 2001 - 11:12:01 CST

Original text of this message

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