Subject Re: [firebird-support] group by problem
Author Ann W. Harrison
apicitos wrote:
>
> select SESASU_ASUNTO as ASUNTO
> from SESASU A join SESGRU G on G.SESGRU_CODIGO = A.SESASU_GRUPO
> where G.SESGRU_MOSTRAR=1 and A.SESASU_SESION=1049
> union
> select F_STRBLOB(G.SESGRU_DESCRIP) as ASUNTO
> from SESASU A join SESGRU G on G.SESGRU_CODIGO = A.SESASU_GRUPO
> where G.SESGRU_MOSTRAR=0 and A.SESASU_SESION=1049
> group by G.SESGRU_CODIGO
>
> where SESASU_ASUNTO is a blob field and SESGRU_DESCRIP is a varchar.
> I obtain this error message:
> Invalid expression in the select list (not contained in either an
> aggregate function or the GOUP BY clause).
> If supress group by clause it's fine.
> Why?

Because the statement isn't legal SQL. In SQL, the select list for a
grouped query can not include simple fields that are not in the group by
clause, even if you know that there is a one-to-one correspondence
between a grouping field (SESGRU_CODIGO) and the other field. This rule
eliminates nonsense queries like this:

select name from employees group by department;

but it also eliminates a number of more reasonable queries like yours.

Regards,


Ann