
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How is it possible to filter out the duplications in the rows of result set return by MySQL?
It can be possible by using the DISTINCT keyword in SELECT clause. The DISTINCT applies to the combination of all data fields specified in SELECT clause.
Example
We have the table ‘Student’ on which we have applied DISTINCT keyword as follows −
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)
- Related Articles
- In MySQL, how can we randomize set of rows or values in the result set?
- How can we get all the unique rows in MySQL result set?
- While using the ROLLUP modifier, is it possible to use a MySQL ORDER BY clause to sort the result?
- What is the meaning of ‘empty set’ in MySQL result set?
- How to filter rows in Pandas by regex?
- What is the importance of the order of Columns in the SET clause of UPDATE statement? Will it make big difference in result set returned by MySQL?
- MySQL “order by” inside of “group by”? Is it possible?
- How to select most recent date out of a set of several possible timestamps in MySQL?
- How can we divide the result set returned by MySQL into groups?
- Is it possible to add a set of elements in one cell with MySQL?
- Write a MySQL query to check if field exists and then return the result set?
- How to make MySQL result set the same as specified?
- How to sort MySQL output on the basis of the column which is not in the result set?
- Set the result of a query to a variable in MySQL?
- How to return rows that have the same column values in MySQL?

Advertisements