Ordering IN()

This post is not about DoorDash or SkipTheDishes, it’s about using the Where IN() clause in SQL. Yesterday I thought I had discovered a way to order the inclusion of child records since this StackOverflow answer led me to believe that ordering values in the IN() clause will in fact order the resultset in Firebird. Unfortunately, in my testing with Firebird 3.04 this is not the case.

So beware, StackOverflow can be a great source of information, but it’s not always correct. It’s also of course better to explicitly order results rather than rely on the behaviour of a query processing engine so I will be re-writing the Marshmellow code used to generate the query.

One Response to “Ordering IN()”

  1. thinker Says:

    If you want to have things ordered in the SQL result, you ALWAYS have to use ORDER BY.

    Otherwise it up to the database server to give you the result in the “order” it see fit at each call. And note that this can vary depending on the SQL engine execution plan too.

Leave a Reply