Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Apply distinct on Three column

Author  Topic 

yaman
Posting Yak Master

213 Posts

Posted - 2010-03-29 : 14:58:08
Sir ,

How can i apply distinct on three column out of ten colum .
Please help me out sir ,

Yaman

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-29 : 15:59:30
You could use a GROUP BY, however we need to see some sample data to determine what query to use. You probably will need a derived table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-30 : 13:22:20
one way is as follows

SELECT t. required columns here....
FROM YourTable t
INNER JOIN (SELECT Col1,Col2,Col3,MIN(PK) AS First
FROM YourTable
GROUP BY Col1,Col2,Col3)t1
ON t1.Col1 = t.Col1
AND t1.Col2 = t.Col2
AND t1.Col3 = t.Col3
AND t1.First=t.PK

Col1,Col2,Col3 is columns for which you need distinct combination

PK is your primary key

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -