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 many partitions a clustered index has by default in sql server 2012?
What are the 2 types of classifications of constraints in the sql server?
Is sql server free?
on line cluster can we make if yes tell me the procedure
How to provide column names in insert statements in ms sql server?
What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting is possible?
Explain what is the main purpose of having conversation group?
How to perform backup for certificates in sql server? : sql server security
Why functions are used in sql server?
Can you move the resources after pausing the node? : sql server database administration
What is collation?
How to write an inner join with the where clause in ms sql server?
How can I tell if sql server is 32 or 64 bit?
What do you mean by tablesample?
What command do we use to rename a db, a table and a column?