FIX: Subquery with ORDER BY may Return Results in Wrong Order

This article was previously published under Q246201
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 56519 (SQLBUG_70)
SYMPTOMS
The ORDER BY clause of a SELECT statement may be ignored when the sub-select statement also contains an ORDER BY clause. For example, the following query returns results in the wrong order:
use pubsselect * FROM (select top 3 * from authors     where au_lname < 'MacFeather'     order by au_lname desc) as aorder by au_lname				
The three results rows should be ordered "Hunter", "Karsen", "Locksley" but the results are reversed.
WORKAROUND
Instead of using "*" to return all columns in the table, specify the column names explicitly. The following query works as expected:
use pubsselect au_id, au_lname, au_fname, phone, address, city, state, zip, contract FROM (select top 3 * from authors     where au_lname < 'MacFeather'     order by au_lname desc) as aorder by au_lname				
STATUS
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.
Properties

Article ID: 246201 - Last Review: 12/05/2015 17:31:25 - Revision: 2.1

Microsoft SQL Server 7.0 Standard Edition

  • kbnosurvey kbarchive kbbug kbfix KB246201
Feedback