Skip to content

Fix ORDER BY on grouped source columns when SELECT uses aliases - #2525

Draft
mathiasrw with Copilot wants to merge 2 commits into
developfrom
copilot/fix-order-by-clause-issue
Draft

Fix ORDER BY on grouped source columns when SELECT uses aliases#2525
mathiasrw with Copilot wants to merge 2 commits into
developfrom
copilot/fix-order-by-clause-issue

Conversation

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Grouped queries were not honoring ORDER BY when the sort referenced the original grouped column name but the SELECT list exposed that column under an alias. This caused grouped results to remain in input order instead of being sorted.

  • Grouped ORDER BY key resolution

    • Update grouped select compilation to resolve ORDER BY keys from the grouped source column when the output row only contains the aliased projection.
    • Preserve existing behavior for ordering by projected names and other grouped expressions.
  • Regression coverage

    • Add an issue-focused test covering GROUP BY with aliased projections and ORDER BY on the original column name.
    • Cover both ascending and descending ordering.
alasql(
  'SELECT num AS position, letter AS note FROM ? GROUP BY num, letter ORDER BY num',
  [[
    {num: 100, letter: 'one'},
    {num: 50, letter: 'two'},
    {num: 10, letter: 'two'}
  ]]
);

// before: [{position:100}, {position:50}, {position:10}]
// after:  [{position:10}, {position:50}, {position:100}]

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ORDER BY clause sorting issue with GROUP BY Fix ORDER BY on grouped source columns when SELECT uses aliases Aug 20, 2026
Copilot AI requested a review from mathiasrw August 20, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with ORDER BY clause by original column name when GROUP BY used

2 participants