SQL SELECT UNIQUE

Actually, there is no difference between DISTINCT and UNIQUE.

SELECT UNIQUE is an old syntax which was used in oracle description but later ANSI standard defines DISTINCT as the official keyword.

After that oracle also added The distinct statement is used to fetch unique records from table The distinct sql statement removes duplicate records from fetched data.The distinct statement is used with Select statement.


Note: SQL SELECT UNIQUE and SQL SELECT DISTINCT statements are same.



The DISTINCT keyword can be used to return only distinct (different) values.

SQL SELECT DISTINCT Syntax

SELECT DISTINCT column_name,column_name

FROM table_name;

Let's try to understand it by the table given below:

Student Name Gender Mobile Home Town
Harish Sharma Male 9711195889 Ghaziabad
Mithilesh Singh Male 9450583625 Noida
Rahul Singh Male 8860449650 Delhi

The following SQL statement selects only the distinct values from the "City" columns from the "Customers" table:

SELECT DISTINCT gender FROM student ;

SQL SELECT COUNT

The SQL COUNT() function is used to return the number of rows in a query. The count() function is generally used in SQL SELECT function. It is very useful to count the numbers of records.

Let's see the syntax of SQL COUNT statement.


SELECT COUNT (expression)   

FROM tables   

WHERE conditions;

Let's see the examples of sql select count function.

SQL SELECT COUNT(column_name)

SELECT COUNT(name) FROM employee_table;

It will return the total number of names of employee_table. But null fields will not be counted.

SSQL SELECT COUNT(*)

SELECT COUNT(*) FROM employee_table;

The "select count(*) from table" is used to return the number of records in table.