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
How you can get a list of all the table constraints in a database?
What is the use of sql profiler in sql server 2012?
What are the benefits of normalization?
How to use user defined functions in expressions?
What command is used to create a database in the sql server and how?
How to find out what is the default collation in a database?
What are the various editions of sql server 2017 that are available in the market?
What is merge?
What are the basic functions for master, msdb, model, tempdb and resource databases?
What are data driven subscriptions?
Explain atomicity?
What are the new features in SQL Server 2005 when compared to SQL Server 2000?
Explain the disadvantages of cursors?
How do I determine how many instances of sql server are installed on a computer?
What are indexes in ms sql server?