Subject Invalid expression in the select list Error
Author Roland Chie
Can someone please help me out with this query? When I try to
execute it give this error "Invalid expression in the select list
(not contained in either an aggregate function or the GROUP BY
clause)." The error comes in when I added the subselect but it
returns a single value

select
d.header,
case when (n.reference is null) then
case when d.upccode = '' then d.plu
else
d.upccode
end
else
case when n.upccode = '' then n.plu
else
n.upccode
end
end as UPCCode,
h.manufacturer,
h.brand,
g.description as category,
case when (n.reference is null) then
d.description
else
n.description
end as description,
(select first(1)nn.description from itemdetails nn
where nn.upccode = n.upccode and
nn.plu = n.plu and
nn.unitcount = n.unitcount) as conDescription,
sum(case when (n.reference is null) then coalesce(s.onHand,0)
else
(coalesce(s.onHand,0) * d.unitcount)/n.unitcount
end) as onhnahd,
sum(coalesce(sc.cost,0) * coalesce(s.onhand,0)) as costvalue,
sum((coalesce(sp.price,0)-coalesce(sb.buydown,0)) * coalesce
(s.onhand,0)) as retailvalue,
sum(((coalesce(sp.price,0)-coalesce(sb.buydown,0)) * coalesce
(s.onhand,0))-
(coalesce(sc.cost,0) * coalesce(s.onhand,0))) as profit
from itemdetails d
left join itemdetails n on (n.header = d.header and n.description
='Consolidator')
left join itemheaders h on (h.reference = d.header)
left join categories g on (g.reference = h.category)
join departments dp on (dp.reference = h.department)
left join stocks s on (s.item = d.reference)
left join storecosts sc on (sc.item = d.reference)
left join icrcurrentitemprice(d.reference) sp on (d.reference =
d.reference)
left join icrcurrentitembuydown(d.reference) sb on (d.reference =
d.reference)
Where
((d.Deleted is null) and (d.description <> 'Consolidator'))
group by 1,2,3,4,5,6,7
order by 1,3,4,5