select sequence WITHOUT (sufficient) order by

  • I have a query that in fact uses ORDER BY but not on enough columns to make each row unique on these columns. Someone else has a similar query, structured a little differently but essentially returning the same data. The two queries are returning data in slightly different order.

    I intend to extend the order by clause to resolve the issue. However the lists are public and the order is "sensitive" ( a waiting list )

    If instead of extending the order by clause, I made my query identical to the other one:

    1) Would I always get the same results as the other query ?

    2) Would I get the same results day after day ?

    The data is in fact quite dynamic but it is important that both queries return the same order.

  • john-645829 (10/1/2010)


    I have a query that in fact uses ORDER BY but not on enough columns to make each row unique on these columns. Someone else has a similar query, structured a little differently but essentially returning the same data. The two queries are returning data in slightly different order.

    I intend to extend the order by clause to resolve the issue. However the lists are public and the order is "sensitive" ( a waiting list )

    If instead of extending the order by clause, I made my query identical to the other one:

    1) Would I always get the same results as the other query ?

    2) Would I get the same results day after day ?

    The data is in fact quite dynamic but it is important that both queries return the same order.

    Hi John,

    The answer to both questions is "no". The order might be the same when you test it, and it might even continue to be the same for a very long time, but this is not guaranteed - if it remains the same, you are just lucky,

    The only guarantee given by the ORDER BY is the that the specified ordering is applied; rows with identical values in the ORDER BY columns can be in any order. If you want controle over that order, add tiee-breaker columns to the ORDER BY until you get a list of columns whhere no rows will ever have duplicate values.

    BTW, you seem to have misplaced this question. I hope a moderator will move it to a more appropriate location.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This reply has been reported for inappropriate content.

    The complete look of your internet site is remarkable, not to mention the content material!

    also visit my net web page business pages

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply