Reputation: 460
I'm trying select the unique records from my table. My table contains nearly 20 columns and more than 500 000 records.
Sample data:
Desired Result:
I have used the following query, It returns the result which I need but taking lot of time to load the output.
SELECT [C1],[C2],[C3],[C4]
FROM [dbo].[result]
WHERE [C1] = (
SELECT MIN(C1)
FROM [dbo].[result] AS F
WHERE F.C2 = [dbo].[result].C2)
Is there any way to speed my query?
Upvotes: 0
Views: 43
Reputation: 55806
Try with:
SELECT First([C1]) As Id, [C2], [C3], [C4]
FROM [dbo].[result]
GROUP BY [C2], [C3], [C4]
Upvotes: 1