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
Give an example of why you would want to denormalize a database
What samples and sample databases are provided by microsoft?
How to drop an existing table?
When is the use of update_statistics command?
What options are available to audit login activity? : sql server security
What is catalog views?
What is the use of attributehierarchyvisible ? : sql server analysis services, ssas
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?
What do mean by xml datatype?
What is an entity-relationship diagram (erd)?
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.
How to use clusters?
Explain use of expression builder.
Can I run multiple instances of sql server 2000 at the same time on one computer?
What is a transaction and why is it important?