Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

SQL Distinct Keyword

 


SQL Distinct Keyword

The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records.

There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records.

 

Syntax:

The basic syntax of DISTINCT keyword to eliminate duplicate records is as follows:

 

SELECT DISTINCT column1, column2,.....columnN

FROM table_name

WHERE [condition]

 

Example:

Consider the CUSTOMERS table having the following records with some repetition:

+----+-------------+------+-----------------+---------------+

| ID  | NAME      | AGE  | ADDRESS      | SALARY       |

+----+-------------+------+-----------------+---------------+

| 1    | Ramesh   | 32    | Ahmedabad   | 2000.00      |

| 2    | Ramesh   | 25    | Delhi                | 1500.00      |

| 3    | kaushik   | 23    | Kota                 | 2000.00      |

| 4    | Chaitali    | 25   | Mumbai          | 6500.00       |

| 5    | Chaitali    | 27    | Bhopal            | 8500.00       |

| 6    | Komal      | 22    | MP                   | 4500.00       |

| 7    | Muffy       | 24    | Indore            | 10000.00     |

+----+-------------+------+-----------------+---------------+

 

Let us use DISTINCT keyword with the above SELECT query and see the result:

 

SQL> SELECT DISTINCT SALARY FROM CUSTOMERS

ORDER BY SALARY;

 

This would produce the following result where we do not have any duplicate entry:

+---------------+

| SALARY       |

+---------------+

| 1500.00      |

| 2000.00      | 

| 4500.00      |

| 6500.00      |

| 8500.00      |

| 10000.00   |

+---------------+

 





आशा करते है कि हमारे द्वारा लिखी हुई इस Post को आप Like, Share and Comment करेंगे | और हमें Comment करके बताये की आपको ये Post कैसी लगी | इसी तरह की Post और News पाने के लिए हमारे सभी Social Media Channels को रेगुलर Follow करे| 


Thanks
Amar Digital World
(Always Ready To Digital Serve)

Post a Comment

0 Comments