34,871
社区成员




select distinct id from tb order by id,name
/*
消息 145,级别 15,状态 1,第 1 行
如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-09-20 17:25:29
-- Verstion:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
-- Apr 22 2011 11:57:00
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[col] int)
insert [tb]
select 1,4 union all
select 1,4 union all
select 2,5 union all
select 3,6
--------------开始查询--------------------------
select id from tb order by name
----------------结果----------------------------
/* 消息 207,级别 16,状态 1,第 8 行
列名 'name' 无效。
*/