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?
How to get a list of columns using the "sys.columns" view in ms sql server?
How do I run sql server 2014?
Explain what is public role in sql server?
Why are views required in the sql server or in any other database?
What is SQL Server?
can a database be shrunk to 0 bytes, if not, why? : Sql server administration
When would you use the stored procedures or functions?
What is explicit cursors?
What are the tools available in market as an alternative to sql server reporting services?
Why we use the openxml clause?
What do you understand by the data quality services in sql server?
What are the source of constraints?
How to include date and time values in sql statements?
What is Command line parameters in PLSQL.?