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 drop an existing schema in ms sql server?

1101


How to receive returning result from a query?

1124


List out the difference between union and union all in sql server?

989


Explain the difference between cross join and full outer join?

980


You want to implement the many-to-many relationship while designing tables. How would you do it?

997


What are the different types of Indexes available in SQL Server?

1008


What is update locks?

886


What is the difference between implicit and explicit transaction?

1010


what information is maintained within the msdb database? : Sql server administration

972


Explain different backup plans?

942


How to create dbo table in sql server?

950


What is unpivot?

1011


What is partition, how will you implement it? : sql server analysis services, ssas

1047


Hi all, can any one please tell me the difference between sql server 2008 and orace 9i

1945


IF more than one Site is accessing the same Database server and I want to move the DB with Minimum down time? How will you do

1805