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
can you instantiate a com object by using t-sql? : Sql server database administration
How can I create a new template for import ? : sql server management studio
Explain what stored procedure sp_replcounters is used for? : sql server replication
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 many triggers you can have on a table? : Sql server database administration
What are views in ms sql server?
What is the recovery model? List the types of recovery model available in sql server?
‘Order by’ is not allowed in a view how can you sort information from a view?
What is user-defined inline table-valued function?
You want to be sure that queries in a database always execute at the maximum possible speed. To achieve this goal you have created various indexes on tables which other statement will keep the database in good condition?
Where are sql server usernames and passwords stored in the sql server?
What is meant by referential integrity?
Ways to improve the performance of a SQL Azure Database?
plss anybody specify tha constrian management system in dbms
What is the difference between Stored Procedures and triggers?