[ 
https://issues.apache.org/jira/browse/DERBY-6909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16134493#comment-16134493
 ] 

Bryan Pendleton commented on DERBY-6909:
----------------------------------------

That is correct; the query  "select * from TEST group by upper(name), 
upper(label);" is not a valid GROUP BY query.

In table TEST, "*" expands to "name, label".

You can't "select *" in your GROUP by query because you didn't group by 
name,label; you can only select the values you have grouped by, or aggregated 
results over those groups. This StackOverflow question gives some good 
background about why SQL behaves this way: 
https://stackoverflow.com/q/11991079/193453

So "select name from test group by name" is valid, because you are selecting 
the grouped column. But "select * from test group by name" is not, because 
column label is not grouped by.

> Invalid grouping by multiple columns when use function (Apache Derby 
> 10.10.2.0)
> -------------------------------------------------------------------------------
>
>                 Key: DERBY-6909
>                 URL: https://issues.apache.org/jira/browse/DERBY-6909
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.10.2.0, 10.13.1.1
>            Reporter: Boris Brinza
>            Assignee: Indumini Ayomi
>            Priority: Minor
>              Labels: queries
>         Attachments: derby.log
>
>
> Create table TEST:
> create table TEST (name varchar(10), label varchar(10));
> insert into TEST values ('johnny', 'label_1');
> insert into TEST values ('johnny', 'label_2');
> These queries returns 2 rows 'JOHNNY':
> select upper(name) from TEST group by name, label
> select upper(name) from TEST group by upper(name), label
> When grouping is changed this way, query returns only 1 row 'JOHNNY':
> select upper(name) from TEST group by upper(name), upper(label)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to