可以透過在 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)
以上是MySQL傳回結果集的行中如何篩選掉重複的行?的詳細內容。更多資訊請關注PHP中文網其他相關文章!