title: Disambiguating columns used in group by that come from select
body: <p>Assume a table <code>person</code> exists with columns id, first_name, last_name and table 'dog' exists with columns id, owner_id, name exist.</p>
  <p>Take the following query:</p>
  <pre><code>Select
    first_name + last_name as name,
    count(*) dog_count
  from
    person
    join dogs on person.id = dog.owner_id
  group by
    person.id,
    first_name + last_name;
  </code></pre>
  <p>This query works and for this purpose, but has 1 thing that erks me whenever I have to write group by clauses and I went searching for solutions today and didn't really ever find one that I liked.</p>
  <p><code>name</code> from the query select clause doesn't exist when it processes the group by (due to the order of execution). Many RDMS allow it anyways as an extension, but even most (I think all) of those will run afoul of the following problem: if I use <code>name</code> instead of <code>first_name + last_name</code> in the group by clause, instead of going to the select clause to use name from there it'll to go <code>name</code> from the dog table.</p>
  <p>I don't know if it's part of the standard, but many RDMS allow you to use column numbers instead to specify columns from the select, so I can do <code>group by 1</code>, but this becomes problematic with larger queries that may be dynamically specifying columns so that the ordering may change.</p>
  <p>So... the final question: does any RDMS that anybody is aware of have a way to disambiguate by column name (or other consistent attribute) when pulling columns from the select clause? An example of something that could work would be <code>group by select.name</code> to specify 'take the column <code>name</code> from the select clause and apply it to the group by clause`?</p>
  <p>Does anybody know if discussion on the topic has ever been brought as something to make it into SQL standards?</p>