
- 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 can we get only unique values of a column in MySQL result set?
While querying data from a MySQL table, we may get duplicate values from a column. With the help of the DISTINCT clause in the SELECT statement, we can get rid of duplicate data in the result set.
Syntax
SELECT DISTINCT Columns FROM Table_name WHERE conditions;
Example
For example, we have a table named ‘tender’ having the following columns −
mysql> Select * from tender; +----------+--------------+--------------+-------+ | clientid | client_Fname | Client_Lname | value | +----------+--------------+--------------+-------+ | 100 | Mohan | Kumar | 60000 | | 101 | Sohan | Singh | 50000 | | 101 | Somil | Rattan | 55000 | | 103 | Gaurav | Kumar | 75000 | | 103 | Rahul | Singh | 63000 | +----------+--------------+--------------+-------+ 5 rows in set (0.00 sec)
Now, if we want to get only the unique values of the column named ‘Client_Lname’ then following would be query −
mysql> Select DISTINCT client_Lname from tender; +--------------+ | client_Lname | +--------------+ | Kumar | | Singh | | Rattan | +--------------+ 3 rows in set (0.05 sec)
The query below will do the same with a column named ‘client_Fname’.
mysql> Select DISTINCT client_Fname from tender; +--------------+ | client_Fname | +--------------+ | Mohan | | Sohan | | Somil | | Gaurav | | Rahul | +--------------+ 5 rows in set (0.00 sec)
- Related Articles
- How can we get all the unique rows in MySQL result set?
- How can we get the summary output of a column in MySQL result set itself?
- How can we count a number of unique values in a column in MySQL table?
- In MySQL, how can we randomize set of rows or values in the result set?
- Get the count of only unique rows in a MySQL column?
- How can we handle a result set inside MySQL stored procedure?
- Get count of values that only appear once in a MySQL column?
- Can we replace a number with a String in a MySQL result set?
- How can we use MySQL SUM() function to calculate the sum of only dissimilar values of the column?
- How can we divide the result set returned by MySQL into groups?
- How can we get randomly different set of rows or values each time from MySQL table?
- Python Pandas - Get unique values from a column
- How can we fetch a MySQL SET column as a list of integer offset?
- How can I get the records from MySQL table in result set in a particular way?
- Can we skip a column name while inserting values in MySQL?

Advertisements