Home / mySQL / Retrieve the unique rows without using the DISTINCT keyword

Retrieve the unique rows without using the DISTINCT keyword

Good Morning to all,
We know the uses of DISTINCT keyword in SQL. Here I share some usesful information relates to “Retrieve the unique rows without using the DISTINCT keyword.”
The DISTINCT keyword is used to return only distinct or different values. In table, the column may contain many duplicate values, and if you want to display the list the different values by using DISTINCT keyword in select query.



SQL SELECT DISTINCT Syntax

SELECT DISTINCT column_name,column_name FROM table_name;

Example:Employee table





EmployeeID employee_name
1 Thomas
2 Varghese
3 Jose
4 Varghese

SELECT DISTINCT employee_name FROM Employee;

OUTPUT





employee_name
Thomas
Varghese
Jose

How would you retrieve the unique values for the employee_name without using the DISTINCT keyword

GROUP BY keyword helps to retrieve the unique values in sql

SELECT employee_name from Employee GROUP BY employee_name

Running this query will return the following results:


employee_name
Thomas
Varghese
Jose




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com