Select*fromtender;+----------+---------- ----+--------------+-------+|clientid|client_Fnam"/> Select*fromtender;+----------+---------- ----+--------------+-------+|clientid|client_Fnam">
While querying data from a MySQL table, we may get duplicate values from columns. With the help of the DISTINCT clause in the SELECT statement, we can remove duplicate data from the result set.
SELECT DISTINCT Columns FROM Table_name WHERE conditions;
For example, we have a table named "tender" which contains 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 the following will be the query -
mysql> Select DISTINCT client_Lname from tender; +--------------+ | client_Lname | +--------------+ | Kumar | | Singh | | Rattan | +--------------+ 3 rows in set (0.05 sec)
The following query will get the unique values of the column named "client_Fname" Columns perform the same operation.
mysql> Select DISTINCT client_Fname from tender; +--------------+ | client_Fname | +--------------+ | Mohan | | Sohan | | Somil | | Gaurav | | Rahul | +--------------+ 5 rows in set (0.00 sec)
The above is the detailed content of How can I get the unique value of a column in a MySQL result set?. For more information, please follow other related articles on the PHP Chinese website!