What would be the best way to avoid distinct clause in query to get the result.My Query looks like
select distinct Col1 ,col2,col3,col4 from ABC where (1=1) group by Col1 ,col2,col3,col4 order by col1
ABC Contains records like
Col1 col2 col3 col4
a 1 1 1
a 2 1 1
B 2 2 2
B 1 1 1
;
;
;
how is the performance of disticnt query on Number of Rows ? HOw can i Improve my query performance if want to use distinct in my query? will adding indexes help to boost performance?
Thanks
You didn't tell us what is your desired outcome...
The WHERE clause can be removed.
The GROUP BY forces what you display.
Do you wish to collapse so that all 'a'/'B', etc is in one row?
If so, then something like:
Code Snippet
SELECT
Col1,
col2 = sum( Col2 ),
Col3 = sum( Col3 ),
Col4 = sum( Col4 )
FROM ABC
GROUP BY Col1
No comments:
Post a Comment