Menu

#373 group and order by using column indexes

open
nobody
None
5
2024-11-10
2024-11-10
No

Is there any chance group and order by are allowed to start using column indexes instead of repeating the expressions that are in the select part? For example: "group by 1,2,3 order by 2".

This makes queries much more compact, more readable and less error prone. In case of the example, if 2 were a calculated field using CASE, that code is present three times.

Discussion

  • Fred Toussi

    Fred Toussi - 2024-11-10

    It is already possible to use column indexes in ORDER BY.

    Aliases for expressions are also supported. They are compact and less error-prone in case you later edit the query. For example:

    SELECT MAX(id) m, firstname f, city c FROM customer GROUP by f, c ORDER BY m

     
    • Tom Eugelink

      Tom Eugelink - 2024-11-10

      That is even better. I missed that in the documentation?

       

Log in to post a comment.

MongoDB Logo MongoDB