• sachin6139 (6/4/2013)


    I have 2 select statements. One with NOLOCK hint and other without NOLOCK hint. I am getting different result sets. Rows are same but there order is different. Why?

    SQLServer never, ever guarantees that results will be in any order unless an explicit ORDER BY is added to a query.

    If order is important, you have to tell SQL to use an Order By.

    the engine will use various indexes to get the data in what it determines is the fastest way possible; because the two queries are not the same, the apparent order is not duplicated between the two.

    even the same query repeated multiple times can be affected by parallelism, SET options, statsitics being updated and much much more.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!