Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eliminate same kind of pairs

Status
Not open for further replies.

amie8202

Programmer
Aug 16, 2004
4
US
Hi,
I have a table A like something like this:
| a b c d
--|----------------
1|(1, 2), (0, 0)
2|(3, 1), (1, 2)
3|(0, 0), (3, 1)
4|(0, 0), (1, 2)

In this, I want to eliminate the duplicate where there is same kind of pair (1,2) (0,0) and (0,0) (1,2).
So I would just end up with 3 rows of table
with eliminate either of that pairs...

How do I do this with sql command???

Thanks in advance!!
 
delete a
from TableA a

inner join TableA b
on ( (a.col1 = b.col3)
and (a.col2 = b.col4)
and (b.col1 = a.col3)
and (b.col2 = a.col4))

where not
( (a.col1 = b.col1)
and (a.col2 = b.col2)
and (a.col3 = b.col3)
and (a.col4 = b.col4))

-- this will delete the value with the largest numbers in the first two columns,
-- to remove the smaller switch signs
-- this won't work if all the numbers are duplicated
and ((a.col1 > b.col1)
or (a.col2 > b.col2))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top