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
What is model database in sql server?
What is executereader?
What do you mean by tablesample?
what is create database syntax? : Sql server database administration
How to test odbc dsn connection settings?
Explain what you mean by 3 tier architecture.
How to name query output columns in ms sql server?
Explain user defined views?
What are the kinds of subquery?
Can we use pragma autonomous_transaction in trigger?
you have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem? : Sql server administration
How to create new databases with "create database" statements?
What are page splits? : SQL Server Architecture
What do mean by xml datatype?
How to create a simple table to test triggers in ms sql server?