In performance wise distinct is good or group by is good?
eg:select name from emp group by name;
select distinct name from emp;

Answer Posted / madhu

This question is asked many times to me. What is difference
between DISTINCT and GROUP BY?

A DISTINCT and GROUP BY usually generate the same query
plan, so performance should be the same across both query
constructs. GROUP BY should be used to apply aggregate
operators to each group. If all you need is to remove
duplicates then use DISTINCT. If you are using sub-queries
execution plan for that query varies so in that case you
need to check the execution plan before making decision of
which is faster.

Example of DISTINCT:

SELECT DISTINCT Employee, Rank
FROM Employees

Example of GROUP BY:

SELECT Employee, Rank
FROM Employees
GROUP BY Employee, Rank

Is This Answer Correct ?    14 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How you can get a list of all the table constraints in a database?

525


What is the use of sql profiler in sql server 2012?

515


What are the benefits of normalization?

579


How to use user defined functions in expressions?

554


What command is used to create a database in the sql server and how?

609






How to find out what is the default collation in a database?

634


What are the various editions of sql server 2017 that are available in the market?

507


What is merge?

573


What are the basic functions for master, msdb, model, tempdb and resource databases?

557


What are data driven subscriptions?

79


Explain atomicity?

579


What are the new features in SQL Server 2005 when compared to SQL Server 2000?

630


Explain the disadvantages of cursors?

594


How do I determine how many instances of sql server are installed on a computer?

537


What are indexes in ms sql server?

556