一、基本使用
distinct一般是用来去除查询结果中的重复记录的,而且这个语句在select、insert、delete和update中只可以在select中使用,具体的语法如下:
select distinct expression[,expression...] from tables [where conditions];
1.1 只对一列操作
这种操作是最常见和简单的,如下:
select distinct country from person
1.2 对多列进行操作
select distinct country, province from person
1.3 针对NULL
的处理
从1.1和1.2中都可以看出,distinct
对NULL
是不进行过滤的,即返回的结果中是包含NULL
值的。