diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 279aef7868..58a987dc89 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -657,10 +657,13 @@ class BaseModelSqlv2 { qb, ); - if (!sorts) - sorts = args.sortArr?.length - ? args.sortArr - : await Sort.list({ viewId: this.viewId }); + if (!sorts) { + if (args.sortArr?.length) { + sorts = args.sortArr; + } else if (this.viewId) { + sorts = await Sort.list({ viewId: this.viewId }); + } + } // if sort is provided filter out the group by columns sort and apply // since we are grouping by the column and applying sort on any other column is not required