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


Please Help Members By Posting Answers For Below Questions

How many partitions a clustered index has by default in sql server 2012?

661


What are the 2 types of classifications of constraints in the sql server?

586


Is sql server free?

526


on line cluster can we make if yes tell me the procedure

1517


How to provide column names in insert statements in ms sql server?

606






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?

490


Explain what is the main purpose of having conversation group?

525


How to perform backup for certificates in sql server? : sql server security

597


Why functions are used in sql server?

504


Can you move the resources after pausing the node? : sql server database administration

596


What is collation?

715


How to write an inner join with the where clause in ms sql server?

557


How can I tell if sql server is 32 or 64 bit?

501


What do you mean by tablesample?

639


What command do we use to rename a db, a table and a column?

506