Skip to main content

DISTINCT and COUNT Operator in SQL

DISTINCT  in SQL Statement;
                                                The DISTINCT keyword in SELECT is used to retrieve unique value from database table. It used to eliminates the duplicate row from the database table.

 SELECT DISTINCT column_name FROM table_name WHERE condition
Employee
 id     Emp_name      Age         Salary Dept_id Location
 1 Jebas  35 55000 2 TVL
 2             Thomas  30 70000 1 TVL
 3 Mark              25 55000 2 TEN
 4         Harry  42 55000 2 TUTY
 5 Willam  45 70000 1 TUTY
 6 James  32 45000 3 TEN
 7 Mock  22 45000 3
 KOVI
 8 Sherin  23 12000 7 TUTY
SELECT  DISTINCT(Location )
  FROM Employee salary;
This statement return distinct location of employee.
Employee
 Location
 KOVI      
 MDY       
 TEN       
 TUTY      
 TVL

COUNT in SQL Statement.
                                    The COUNT is used return the number of rows in table.
SELECT COUNT(column_name) FROM table_name;
Example;
SELECT COUNT(Emp_name) FROM Employee;
This number of employee in table
Employee
 8

SELECT count( DISTINCT location)
  FROM Employee ;
This query return number of distinct location from which employee come.
Employee
5


Thank You. Like Share and Subscribe 👍 folowlect.com

Comments