sql - Firebird group clause -
i can't understand firebird group logic
query:
select t.id t1 t inner join t2 j on j.id = t.jid t.id = 1 group t.id
works perfectly
but when try other fields:
select * t1 t inner join t2 j on j.id = t.jid t.id = 1 group t.id
i error: invalid expression in select list (not contained in either aggregate function or group clause)
when use group by
in query, field or fields specified used 'keys', , data rows grouped based on unique combinations of 2 fields. in result set, every such unique combination has 1 , 1 row.
in case, identifier in group t.id
. consider have 2 records in table, both t.id = 1
, having different values column, say, t.name
. if try select both id
, name
columns, directly contradicts constraint 1 group can have 1 row. why cannot select field apart group key.
for aggregate functions different. because, when sum or count values or maximum, performing operation based on id
field, ignoring data in other columns. so, there no issue because there can 1 answer to, say, count of names particular id.
in conclusion, if want show column in results, need group it. however, make grouping more granular, may not desirable. in case, can this:
select * t1 t t.id in (select t.id t1 t inner join t2 j on j.id = t.jid t.id = 1 group t.id)
Comments
Post a Comment