您的位置:首页 > 数据库

Sees like a bug for SQL SERVER 2005

2008-01-17 13:03 369 查看
What do you guess the result of this Query:
SELECT TOP 2 * FROM (SELECT TOP 3 * FROM [SqlBug]) AS T
ORDER BY col1 DESC ;

and this is the scripts for table [SqlBug]:
CREATE TABLE [dbo].[SqlBug](
 [col1] [int] NULL,
 [col2] [nchar](50) COLLATE Chinese_PRC_CI_AS NULL,
 [col3] [int] NULL
) ON [PRIMARY]

the test data in the table is :
col1         col2                                                          col3
1 A                                                  11
2 A                                                  12
3 B                                                  12
4 C                                                  13
5 D                                                  14
6 E                                                  15

My expect result is :
3 B                                                  12
2 A                                                  12
but the real result is :
6 E                                                  15
5 D                                                  14
The "ORDER BY col1 DESC" sentence should act on the outer select but not the inner select. I think it 's most reason is the PRI for "ORDER BY" and parenthesis when used with "Top", so is this a  bug for sql server 2005?
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql server table null query c