Monday, October 6, 2008

Distinct of Data based on a particular Column-TSQL

When we want a distinct of data from a huge DB table (In my case I have 2 lakhs records (0.2 million))

Here ColA has duplicate records based on the ColB data.
We want distinct of ColA and one ColB data. We cannot use the following query.
SELECT DISTINCT ColA, ColB FROM tableA.
Else we have to separately store the distinct values in a DS and then loop through the table again for ColB.
Instead we can use the simple GROUP BY clause
"SELECT tableA.ColA,min([tableA.ColB])FROM tableA GROUP BY [tableA.ColA]"

No comments:

Post a Comment