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

Give an example of why you would want to denormalize a database

503


What samples and sample databases are provided by microsoft?

558


How to drop an existing table?

544


When is the use of update_statistics command?

544


What options are available to audit login activity? : sql server security

627






What is catalog views?

597


What is the use of attributehierarchyvisible ? : sql server analysis services, ssas

561


Due to some maintenance being done, the sql server on a failover cluster needs to be brought down. How do you bring the sql server down?

856


What do mean by xml datatype?

607


What is an entity-relationship diagram (erd)?

577


Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.

2021


How to use clusters?

541


Explain use of expression builder.

557


Can I run multiple instances of sql server 2000 at the same time on one computer?

586


What is a transaction and why is it important?

560