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 to drop an existing schema in ms sql server?
How to receive returning result from a query?
List out the difference between union and union all in sql server?
Explain the difference between cross join and full outer join?
You want to implement the many-to-many relationship while designing tables. How would you do it?
What are the different types of Indexes available in SQL Server?
What is update locks?
What is the difference between implicit and explicit transaction?
what information is maintained within the msdb database? : Sql server administration
Explain different backup plans?
How to create dbo table in sql server?
What is unpivot?
What is partition, how will you implement it? : sql server analysis services, ssas
Hi all, can any one please tell me the difference between sql server 2008 and orace 9i
IF more than one Site is accessing the same Database server and I want to move the DB with Minimum down time? How will you do