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)
 Simple Query?

Author  Topic 

medtech26
Posting Yak Master

169 Posts

Posted - 2008-03-18 : 17:24:39

Hello,

You probably seen this Q before but I have no idea what to search and and therefor any direction would be appreciated.

I have three columns table, two are int and one is datetime (for sorting). I would like to query all values witch are unique within the two integers, however, in some cases data looks like this:
int1 = 1
int2 = 2
and another record like:
int1 = 2
int2 = 1

this pair should be considered as a duplicate and second record should not come with the results set.

Any suggestions?

boesman
Starting Member

1 Post

Posted - 2008-03-18 : 20:15:27
Assuming your table is tb1 and has the two int columns t1 and t2, use:

SELECT DISTINCT CASE WHEN t1 < t2 THEN t1 ELSE t2 END AS tt1, CASE WHEN t1 < t2 THEN t2 ELSE t1 END AS tt2
FROM tb1
Go to Top of Page
   

- Advertisement -