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 how to convert numeric expression data types using the convert() function??
What is SQL Azure Data sync?
Explain how to use linked server?
What are sub reports?
what is the difference between a primary key and a unique key? : Sql server database administration
Explain the flow of creating a cube? : sql server analysis services, ssas
What is nonclustered index with included columns ?
What do you understand by a view?
What is page-level compression?
Does server sql treat char as a variable-length or fixed-length column?
What is updatable resultset?
What are temporal tables in sql server 2016?
What is the beast way to write CTE in SQL Server ?
How is table type constraint applied to a table?
What is user-defined function? Explain its types i.e. Scalar and inline table value user-defined function?