October 10, 2012 at 6:08 am
if i am selecting the some distince records from the large data sets, which is better to use for performence point of view : distinct cluase in select statement or group by clause without some aggregate function.
October 10, 2012 at 6:30 am
If you want to have distinct values u can use distinct otheriwise you want aggreate values for the columns you need to use group by clause. All that depends on your need of data
October 10, 2012 at 6:38 am
actually there is no need to aggregate the some value. only need to identify the distinct records. which also can be possible using the group by clause. so i just want to know which way is better for performence prospects.
October 10, 2012 at 8:12 am
nitin.varshney (10/10/2012)
actually there is no need to aggregate the some value. only need to identify the distinct records. which also can be possible using the group by clause. so i just want to know which way is better for performence prospects.
Have you tried it and looked at the execution plans for each? They will almost always generate the same plan so there is little to no performance difference. As a general rule if there is aggregate data, use group by. If there is no need for aggregation but you just want unique rows, use distinct.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply