Supposing I have a table foo similar to:
ident int, primaryKey, auto_increment
someNumber int
statusId int
...
where the someNumber column is, except for a few special cases, equal to ident. (in those special cases, someNumber is always equal to a previous ident).
I'm seeing problems which give the appearance that a query such as SELECT TOP 10 ident, someNumber FROM foo WHERE statusId=@desiredStatusId ORDER BY someNumber will return the wrong 10 records. The records all have the correct statusId, but randomly there is one whose someNumber is way off. For eaxmple:
ident someNumber
------- ----------
1234567 1234567
1234700 1234700
1234568 1234568
1234569 1234569
1234570 1234570
... ...
What could be causing this query to intermittently return the wrong results?
order byto be respected by the outer query? – Martin Smith Oct 21 '11 at 17:12CREATE TABLEstatement,INSERTstatements to populate the table, and theSELECTthat is returning incorrect results. Chances are we'll immediately be able to find the problem or, even better, you'll see it yourself. – Nick Chammas Oct 21 '11 at 18:04