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
create index myindex on mytable(mycolumn) what type of index will get created after executing the above statement? : Sql server database administration
What is user defined datatypes and when you should go for them?
What are key constraints?
Explain powershell included in sql server 2008?
How many types of objects are there?
How to install sql server 2005 express edition?
You have a table ‘test’ which is a copy of northwind employee table you have written a trigger to update the field ‘hiredate’ with the current date
What is a virtual table in sql?
Explain the purpose of indexes?
What is exporting and importing utility?
What’s the distinction between dropping a info and taking a info offline?
Why we should not use triggers?
How to find table changes in sql server?
How can you hide the sql server instances?
Can a table be moved to different filegroup?