Home > Database > Mysql Tutorial > How can we get all unique rows in MySQL result set?

How can we get all unique rows in MySQL result set?

王林
Release: 2023-08-23 14:13:14
forward
859 people have browsed it

How can we get all unique rows in MySQL result set?

By using the DISTINCT keyword in the SELECT statement, we can get unique rows in the MySQL result set.

Example

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template