Select*fromstudent;+------+---------+---------+ - ----------+|Id |Nama |Alamat|Subjek |+------+---------+--"/> Select*fromstudent;+------+---------+---------+ - ----------+|Id |Nama |Alamat|Subjek |+------+---------+--">
Rumah >pangkalan data >tutorial mysql >Bagaimana untuk menapis baris pendua dalam baris yang dikembalikan oleh MySQL?
Ini boleh dicapai dengan menggunakan kata kunci DISTINCT dalam klausa SELECT. DISTINCT digunakan untuk semua gabungan medan data yang dinyatakan dalam klausa SELECT.
Kami telah menggunakan kata kunci DISTINCT jadual "Pelajar" seperti berikut -
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)
Atas ialah kandungan terperinci Bagaimana untuk menapis baris pendua dalam baris yang dikembalikan oleh MySQL?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!