Icon View Incident Report

Serious Serious
Reported By: Clive Bennett
Reported On: 5/27/2004
For: Version 4.07 Build 1
# 1705 UNION Queries Not Working Properly and Resulting in 0 Records in Result Set

There appears to be a problem with UNION queries. I have been trying to nail down exactly what causes it, and it seems its something to due with aggregate functions. The query below does not return any data (or error), although each SQL statement does return 1 row when executed seperately.

If I remove all of the sum and avg columns it returns the 2 rows correctly.

select 
  project_code,
  c.category_code,
  name,
  sum(units) as total_units,
  avg(units) as avg_units,
  avg( if (nounits,1.0,price)) as avg_price,
  avg(direct_materials_percent) as avg_direct_materials,
  avg(direct_wages_percent) as avg_direct_wages,
  avg(indirect_costs_percent) as avg_indirect_costs,
  avg(surcharge) as avg_surcharge
from 
  category c
  inner join category_detail cd  on c.category_code = cd.category_code 
and c.project_code = cd.project_code
  left outer join exchange_rates e on e.ccy_code = c.ccy_code and e.
period = cd.period and e.project_code = c.project_code
where c.category_code = 11424
group by 
  category_code,project_code,name
UNION
select 
  project_code,
  c.category_code,
  parent.name,
sum(units) as total_units,
avg(units) as avg_units,
avg( if (nounits,1,price)) as avg_price,
avg(direct_materials_percent) as avg_direct_materials,
avg(direct_wages_percent) as avg_direct_wages,
avg(indirect_costs_percent) as avg_indirect_costs,
avg(surcharge) as avg_surcharge
from 
  category c
  inner join category parent on parent.category_code = c.
parent_category_code
  inner join category_detail cd  on c.category_code = cd.category_code 
and c.project_code = cd.project_code
  left outer join exchange_rates e on e.ccy_code = c.ccy_code and e.
period = cd.period and e.project_code = c.project_code
where c.parent_category_code = 11419
group by 
  project_code,parent.name



Comments Comments
The removal of the sum and avg columns was a coincidence and had nothing to do with the problem. The problem was that the code was inadvertently attempting some new INTERSECT processing on UNION queries.


Resolution Resolution
Fixed Problem on 5/27/2004 in version 4.08 build 1
Image