通过在SELECT子句中使用DISTINCT关键字,这是可能的。DISTINCT适用于SELECT子句中指定的所有数据字段的组合。
我们在表'Student'上应用了DISTINCT关键字,如下所示:
mysql> Select * from student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 17 | Raman | Shimla | Computers | | 20 | Gaurav | Jaipur | History | +------+---------+---------+-----------+ 5 rows in set (0.00 sec) mysql> Select DISTINCT Address from student; +---------+ | Address | +---------+ | Delhi | | Mumbai | | Shimla | | Jaipur | +---------+ 4 rows in set (0.00 sec) mysql> Select DISTINCT * from student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 17 | Raman | Shimla | Computers | | 20 | Gaurav | Jaipur | History | +------+---------+---------+-----------+ 5 rows in set (0.00 sec) mysql> Select DISTINCT name from student; +---------+ | name | +---------+ | Gaurav | | Aarav | | Harshit | | Raman | +---------+ 4 rows in set (0.00 sec)