Subject Re: [firebird-support] why won't this query work
Author Gary Benade
Dixon Epperson wrote
> This query gets the error message
> "Invalid expression in the select list (not contained in either an
> aggregate function or the GROUP BY clause) . . ."
>
> SELECT c1.CO_IDNUM, c1.CO_NAME,
> (SELECT SUM(s2.SA_TOTAL)-
> (SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
> (y1.YD_NUM=r1.PY_NUM)
> WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
> '11/23/04'))
> FROM SALESREG s2 WHERE (s2.SA_INVDATE > '10/23/04') AND
> s2.SA_VOID='0' AND s2.SA_CUSTID = c1.CO_IDNUM),
>
> FROM SALESREG s1 LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID = c1.CO_IDNUM)
> GROUP BY c1.CO_NAME, c1.CO_IDNUM order by c1.co_name
>
> The problem comes when I add this second part
> "-
> (SELECT SUM(y1.YD_AMTAPLD) FROM PAYDETAIL y1 JOIN PAYREGISTER r1 ON
> (y1.YD_NUM=r1.PY_NUM)
> WHERE (y1.YD_INV=s2.SA_INVOICE AND y1.YD_VOID='0' AND r1.PY_DATE <=
> '11/23/04'))"
> I've tried moving it outside the first sub select, but then I can't
> see the s2 table,

try changing the group by clause to
GROUP BY c1.CO_NAME, c1.CO_IDNUM, 3 order by c1.co_name

Regards
Gary