Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 to how to convert numeric expression data types using the convert() function??

988


What is SQL Azure Data sync?

119


Explain how to use linked server?

925


What are sub reports?

186


what is the difference between a primary key and a unique key? : Sql server database administration

945


Explain the flow of creating a cube? : sql server analysis services, ssas

1000


What is nonclustered index with included columns ?

905


What do you understand by a view?

932


What is page-level compression?

902


Does server sql treat char as a variable-length or fixed-length column?

950


What is updatable resultset?

932


What are temporal tables in sql server 2016?

838


What is the beast way to write CTE in SQL Server ?

979


How is table type constraint applied to a table?

932


What is user-defined function? Explain its types i.e. Scalar and inline table value user-defined function?

839