From 4cc02dbed115767f835bef14c8fae0db892ee1d3 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Tue, 23 Sep 2025 23:08:31 -0400 Subject: [PATCH] Add regression test for sort order with aggregate term in orderby with groupby --- testing/groupby.test | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testing/groupby.test b/testing/groupby.test index 5af77e952..85a45d6a5 100755 --- a/testing/groupby.test +++ b/testing/groupby.test @@ -326,3 +326,23 @@ sneakers|sneakers|sneakers boots|boots|boots coat|coat|coat accessories|accessories|accessories} + +# make sure we return the group by key sorted DESC when the order by has only an aggregate term +do_execsql_test proper-sort-order { + SELECT u.first_name, COUNT(*) AS c + FROM users u + JOIN products p ON p.id = u.id + GROUP BY u.first_name + ORDER BY c DESC; +} {Travis|1 +Tommy|1 +Rachel|1 +Nicholas|1 +Matthew|1 +Jennifer|1 +Jamie|1 +Edward|1 +Daniel|1 +Cindy|1 +Aimee|1} +