C# 数据库查询语句-第4节.过滤数据(1)
作者:陈钰桃
撰写时间:2022 4月17日
第4节. 过滤数据(1)
- Select Distinct子句
SELECT DISTINCT 子句检索指定列列表中的唯一不同值,换句话说,它从结果集中删除列中的重复值。DISTINCT 子句将所有 NULL 值视为相同的值
语法如下所示:
SELECT DISTINCT column_name1, column_name2 , …
FROM table_name;
A.DISTINCT一个字段的示例
以下语句返回 customers 表中所有客户所在的所有城市:
select distinct city from [sales].[customers]
order by city
B. DISTINCT多列示例
以下语句查找所有客户的不同城市和州。
select distinct city,state from [sales].[customers]
order by state,city
C. DISTINCT带有null值示例
以下示例查找客户的不同(唯一)电话号码:
select distinct null