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 2012 Forums
 Transact-SQL (2012)
 Query to determine that column is unique

Author  Topic 

jackandjill
Starting Member

1 Post

Posted - 2014-10-05 : 00:37:31
How to write a query to determine that if a columns values are unique?
This is just to determine.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-10-05 : 04:43:20
SELECT CASE WHEN min(Col1) < max(col1) then 'Different values' else 'All same value' end
FROM dbo.Table1



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-10-08 : 05:51:37
If the column dont have dupes then that means it has unique values right..check for the dupes

Hema Sunder
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-10-08 : 06:48:03
If values are not unique, below query should return some result:

select col
from table
group by col
having count(*)>1


Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page
   

- Advertisement -