Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

select sequence WITHOUT (sufficient) order by Expand / Collapse
Author
Message
Posted Friday, October 01, 2010 6:09 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 02, 2012 4:23 AM
Points: 61, Visits: 12
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.
Post #996571
Posted Monday, October 04, 2010 3:15 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:32 PM
Points: 5,794, Visits: 8,006
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 MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #997406
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse