TOP CATEGORIES

×

What is the difference between select distinct and group by?

N

Needhi Jadhau

DIFFERENCE BETWEEN SELECT DISTINCT AND GROUP BY IN SQL DATABASE SERVER

SELECT DISTINCT QUERY 

  • The SELECT DISTINCT is used to filter unique records out of the records that satisfy the query criteria.
  • For Example - {SELECT DISTINCT Name, Post FROM Employees;} - In this Distinct query (Name and Post) both are the columns name of the Employees table.
  • DISTINCT will make sure that the same row won’t be returned in the result set twice.
  • DISTINCT can be implemented with a temporary table where execution rows can be checked.
  • DISTINCT queries can be implemented using GROUP BY.

GROUP BY CLAUSE 

  • The "GROUP BY" clause is used when you need to group the data and it should be used to apply aggregate operators to each group.
  • For Example - {SELECT Name, Post FROM Employees GROUP BY Name, Post;} - In this Group By query (Name and Post) both are the columns name of the Employees table.
  • GROUP BY as the name suggests groups the result by some set of parameters and evaluates the whole result set.
  • GROUP BY is implemented based on sorting and the same rules apply to it as well in most of the database.
  • BUT not every GROUP BY query can be translated to DISTINCT.

1 votes

Your Answer

Email: advertise@gdatamart.com

Donate: To Support US

© 2024 GDATAMART.COM (All Rights Reserved)