Home » SQL & PL/SQL » SQL & PL/SQL » Combine queries !!!
Combine queries !!! [message #18409] Wed, 30 January 2002 07:26 Go to next message
Rm69
Messages: 39
Registered: January 2002
Member
How do l combine these two queries into one query

select sum(t.pdincl_retail),
sum(t.pdincl_exempt),
sum(t.pdincl_complaint),sum(t.pdincl_persal)
from exwh.mis_target t,
exch.zw00100p b
where to_char(t.target_date,'yyyy-mm-dd')
='2001-01-01'
and t.branch =to_char(b.branch) and b.region ='5';

select sum(t.pdincl_retail),
sum(t.pdincl_exempt),
sum(t.pdincl_complaint),sum(t.pdincl_persal)
from exwh.mis_target t,
exch.zw30701p O
where to_char(t.target_date,'yyyy-mm-dd')
='2002-01-01'
and t.branch =o.subroker and o.geoarea in ('11','13');
UNION ALL [message #18412 is a reply to message #18409] Wed, 30 January 2002 07:56 Go to previous messageGo to next message
Mike
Messages: 417
Registered: September 1998
Senior Member
Use UNION ALL to combine your 2 queries.

select col1 from x
UNION ALL
select field_a from y
Re: Combine queries !!! [message #18413 is a reply to message #18409] Wed, 30 January 2002 07:58 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
try something like this:
select sum(t.pdincl_retail),
sum(t.pdincl_exempt),
sum(t.pdincl_complaint),sum(t.pdincl_persal)
from exwh.mis_target t,
exch.zw00100p b
where to_char(t.target_date,'yyyy-mm-dd')
='2001-01-01'
and t.branch =to_char(b.branch) and b.region ='5'
UNION ALL
select sum(t.pdincl_retail),
sum(t.pdincl_exempt),
sum(t.pdincl_complaint),sum(t.pdincl_persal)
from exwh.mis_target t,
exch.zw30701p O
where to_char(t.target_date,'yyyy-mm-dd')
='2002-01-01'
and t.branch =o.subroker and o.geoarea in ('11','13');

UNION will eliminate duplicates, UNION ALL won't. Column names and datatypes are derived from the top query.
Previous Topic: DATES
Next Topic: frist three higher values
Goto Forum:
  


Current Time: Sun Aug 09 19:16:59 CDT 2020