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 / selvaraj.v

In SQL Server 2000:
-------------------
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:
--------------------
Query:

select DISTINCT Book_Title,COUNT(*) from bookdetails

Answer:

Server: Msg 8118, Level 16, State 1, Line 1
Column 'bookdetails.Book_Title' is invalid in the select
list because it is not contained in an aggregate function
and there is no GROUP BY clause.

Example of Group By:
--------------------
Query:

select Book_Title,COUNT(*) from bookdetails group by
Book_Title

Answer:

ASP 1
C 1
C++ 1
Oracle 1
SQL Server 1
VB.Net 3
Visual Bsic 1

In this Answer, the VB.NET is Duplicate, it having this
table in 3 times.

Is This Answer Correct ?    5 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a cursor be updated? If yes, how you can protect which columns are updated?

1028


What is the difference between osql and query analyzer?

938


How many primary keys are possible in a table?

872


Explain Capacity planning to create a database? and how to monitor it?

4140


Define Business Edition in SQL Azure?

100


Is it possible to import data directly from t-sql commands without using sql server integration services? If so, what are the commands?

1322


What happens if you delete a table that is used by a view?

939


How does Report Builder support Analysis Services cubes?

147


Why main is user defined function?

945


What is the difference between ddl,dml and dcl commands?

1056


What is serializable?

995


optimization techinques

2632


Can a database be shrunk with users active?

1062


Define indexes?

992


How to verify a user name with sqlcmd tool?

1018