我只有一个数据库表,我需要获得一个没有排序的独特值?
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
答案 0 :(得分:2)
select fieldName
from tblFormsData
group by fieldName
order by min(fieldID)