借助SELECT语句中的DISTINCT关键字,我们可以获得MySQL结果集中的唯一行。
mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 4 | Aarav | | 5 | Ram | | 5 | Ram | | 5 | Ram | +------+-----------+ 7 rows in set (0.00 sec)
如我们所见,表“名称”具有三个重复的行,借助以下查询,我们可以获得仅具有唯一行的结果集。
mysql> Select DISTINCT * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 4 | Aarav | | 5 | Ram | +------+-----------+ 5 rows in set (0.00 sec)