SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select sequence WITHOUT (sufficient) order by


select sequence WITHOUT (sufficient) order by

Author
Message
john-645829
john-645829
Valued Member
Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)

Group: General Forum Members
Points: 69 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.
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11106 Visits: 12002
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search