By using the DISTINCT keyword in the SELECT statement, we can get unique rows in the MySQL result set.
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)
As we can see, the table 'names' has three rows of duplicate data. With the following query, we can get a result set containing only unique rows.
mysql> Select DISTINCT * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 4 | Aarav | | 5 | Ram | +------+-----------+ 5 rows in set (0.00 sec)
The above is the detailed content of How can we get all unique rows in MySQL result set?. For more information, please follow other related articles on the PHP Chinese website!