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 2000 Forums
 Transact-SQL (2000)
 Selecting unique Records in a table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-04 : 08:41:58
Bong writes "Hi there! I posted this inquiry before and haven't received any reply yet. I have a table with 2 fields on it:
Field1 Field2
1 2
2 1
3 4
4 3
5 6

I want to run a query that outputs to a cursor with
the ff. results:
Field1 Field2
1 2
3 4
5 6

I consider recs#2,4 duplicates of recs#1,3. There should
be no more than one occurence of a value in any field.
Need any ideas on how this could be done using SQL code."

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-01-04 : 09:06:52
something like this:

select m1, m2 from t
UNION
select m2, m1 from t
Go to Top of Page

vganesh76
Yak Posting Veteran

64 Posts

Posted - 2005-01-04 : 10:33:06
Hope this works,

Declare @tbl table (i int, j int)
insert into @tbl
select 1 a, 2 b union all
select 2 ,1 union all
select 3, 4 union all
select 4, 3 union all
select 5, 6

SELECT distinct case when j < i then j else i end,
case when i > j then i else j end
from @tbl a


Enjoy working
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-01-06 : 07:31:16
Try this
Select distinct Field1, Field2 from Table where Field1 <=Field2

Madhivanan
Go to Top of Page
   

- Advertisement -