Using SQL SELECT DISTINCT statement for getting distinct values
In MySql SELECT DISTINCT statement is used to get the distinct values from any column. For example suppose a table has a columns with country and we want to know the name of all the countries our table has, so we can use SELECT DISTINCT to get only unique names of the countries.
+----+--------+---------+------+-----------+ | ID | FNAME | LNAME | AGE | COUNTRY | +----+--------+---------+------+-----------+ | 1 | AKSHAY | KUMAR | 12 | INDIA | | 2 | JONTY | RHODES | 40 | CHINA | | 3 | JOHNY | DEPP | 45 | INDIA | | 4 | JESSIE | PINKMAN | 25 | AUSTRALIA | | 5 | JESSIE | JACKSON | 22 | CANADA | +----+--------+---------+------+-----------+
SELECT DISTINCT with syntax and example
SELECT DISTINCT COUNTRY FROM CUSTOMER;
+-----------+ | COUNTRY | +-----------+ | INDIA | | CHINA | | AUSTRALIA | | CANADA | +-----------+ 4 rows in set (0.00 sec)Here we can see that table CUSTOMER has duplicate entries for country coluumn but with the help of DISTINCT we are able to get unique values.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment