
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we get all the unique rows in MySQL result set?
With the help of DISTINCT keyword in SELECT statement, we can get the unique rows in 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)
As we can see that table ‘names’ is having three duplicate rows, with the help of following query we can get the result set having 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)
- Related Questions & Answers
- How can we get only unique values of a column in MySQL result set?
- In MySQL, how can we randomize set of rows or values in the result set?
- How can we get the summary output of a column in MySQL result set itself?
- How can we divide the result set returned by MySQL into groups?
- How can we handle a result set inside MySQL stored procedure?
- How can we delete all rows from a MySQL table?
- How can we get the total number of rows affected by MySQL query?
- How Can MySQL operator precedence affect result set?
- How can we get randomly different set of rows or values each time from MySQL table?
- How can I get the records from MySQL table in result set in a particular way?
- Can we get total number of rows in a MySQL database?
- Get the count of only unique rows in a MySQL column?
- Can we replace a number with a String in a MySQL result set?
- How can we apply filtering criteria at group levels of the result set returned by MySQL?
- How can we get the sorted MySQL output?
Advertisements