sql distinct语法学习

1.介绍

SQL 中distinct用法详解 - 紫陌红尘520 - 博客园

  • distinct 必须放在字段的开头,即放在第一个参数的位置。
  • distinct 忽略 NULL 值:distinct 关键字默认会忽略 NULL 值,即将 NULL 视为相同的值。

distinct语句中select显示的字段只能是distinct指定的字段,其他字段是不可能出现的。

例子:

select distinct name from A;

结果:

和count结合使用:

select count(distinct name) from A;	  --表中name去重后的数目

-- 查询多个字段去重后的数目
select count(*) from (select distinct xing, name from B) AS M;