去重查询
select distinct 字段 from 数据库
(1)查询 tb_students_info 表中所有 age 的执行结果如下所示。
mysql> SELECT age FROM tb_students_info; +------+ | age | +------+ | 25 | | 23 | | 23 | | 22 | | 24 | | 21 | | 22 | | 23 | | 22 | | 23 | +------+ 10 rows in set (0.00 sec)
(2)查询 tb_students_info 表中 age 字段的值,返回 age 字段的值且不得重复,
mysql> SELECT DISTINCT age -> FROM tb_students_info; +------+ | age | +------+ | 25 | | 23 | | 22 | | 24 | | 21 | +------+ 5 rows in set (0.11 sec)