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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 finding Composite unique values ina table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-01-08 : 07:59:48
Saikat writes "I have three columns and none of the columns is a primary key.

Column a has duplicate values , Column b has duplicate values, Column c has fixed valued dor all the rows.

I want to find unique observations for Cola, colb, colc.

Regards,"

madhuotp
Yak Posting Veteran

78 Posts

Posted - 2007-01-08 : 08:47:27
select cola,colb,colc,count(cola),count(colb),count(colc) from <tablename> group by cola,colb,colc having count(cola)+count(colb)+count(colc)>3

the above statement will give u all duplicate composite cola+colb+colc value

next statement will give u composite unique rows

select cola,colb,colc,count(cola),count(colb),count(colc) from <tablename> group by cola,colb,colc having count(cola)+count(colb)+count(colc)=3



Madhu
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 09:12:02
???

SELECT DISTINCT ColA, ColB, ColC
FROM <YourTableNameHere>


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -