mysql> SELECT DISTINCT age FROM student; +------+ | age | +------+ | 18 | | 19 | | 20 | +------+ 3 rows in set (0.00 sec) 对 student 表的 name 和 age 字段进行去重,SQL 语句和运行结果如下:
mysql> SELECT DISTINCT name,age FROM student; +----------+------+ | name | age | +----------+------+ | zhangsan | 18 | | lisi | 19 | | wangwu | 18 | | zhaoliu | 18 | | wangwu | 20 | +----------+------+ 5 rows in set (0.00 sec) 对 student 表中的所有字段进行去重,SQL 语句和运行结果如下: