不对单个表进行排序的SQL查询不同的值?

时间:2013-12-14 14:20:43

标签: sql sql-server

我只有一个数据库表,我需要获得一个没有排序的独特值?

CREATE TABLE [dbo].[tblFormsData](
[fieldID] [int] IDENTITY(1,1) NOT NULL,
[fieldName] [varchar](200) NULL,
[fieldValue] [varchar](max) NULL,
[formType] [int] NULL,
[instantID] [varchar](10) NULL,
[dateCreated] [datetime] NULL,
CONSTRAINT [PK_tblFormsData] PRIMARY KEY CLUSTERED
(
[fieldID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

输入字段名称列

---------------------------
Name 
CPR number
Address
Mobile
Name 
CPR number
Address
Mobile

输出字段名称列

----------------------------
Address
CPR Number
Mobile
Name

输出我需要字段名称列

--------------------------------
Name
CPR Number
Address
Mobile

1 个答案:

答案 0 :(得分:2)

select fieldName
from tblFormsData
group by fieldName
order by min(fieldID)