Quote:
quote:Originally posted by kasanar
But the order of rows in both the result is different.
|
Well, you said that all rows have NULL as the value of your column, so the ISNULL expression will also have the same value for all rows. Thus, you are ordering your resultset on a column where all values "tie". Since you give no other column for (sub)ordering, the query processor is free to return the rows in any old order it wants, as long as the rows meet your original query's ordering. Since all columns have the same value, then any ordering of the rows at all meets your ordering criteria.
The specifics of which rows are actually returned is dependent on indexes, the state of the cache at the instant the query runs, and the phases of the moon... thus you cannot depend on any order unless you specifically request it.
Quote:
|
quote:... If i take 'top - 1' in first query, result shows one particular row even if i tries many times.
|
What would you have it do? If all rows have the same value then it is certainly true that that one row meets your criteria. If you ask for the TOP 1 from a set of rows where the ordering criteria is the same for all rows, then any row is the correct answer. The one it gave you is perfectly correct.
If you have another row in mind, you need to give it more information...
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com