SQL Distinct Clause


SQL Distinct Clause


The SQL DISTINCT clause is used to remove duplicates from the result set.
If we need only distinct columns from the database table then we use SQL Select Distinct Clause.

Syntax:-

                  Select distinct
                                            columnn_name
                                                                        from TableName

This above syntax will remove all duplicates for the required column
If we need to add two columns to remove duplicates then the syntax becomes this:-

                 Select distinct
                                            column1,column2
                                                                           from TableName          

Examples of SQL Distinct Statement:-

1. Select distinct with 1 column:-


                                                              select all departments


                                                             select distinct departments

2. Select distinct with 2 columns:-
                      


                                                                   select two columns without distinct
                                                                 select two columns with distinct

NOTE:-  If table have null data in few columns then it will return only one null value
               

In this tutorial, you learned how we can use SQL Distinct Clause.



Comments :

Post a Comment