DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   cross data please heslp (http://www.daniweb.com/forums/thread78533.html)

rado May 16th, 2007 7:15 pm
cross data please heslp
 
i have table
(id1,id2)
1.row [1,2]
2.row [2,1]
3.row [3,4]
4.row [4,3]
5.row [5,6]
6.row [6,5]

i want to get result:

1.row [1,2]
3.row [3,4]
5.row [5,6]

or

2.row [2,1]
4.row [4,3]
6.row [6,5]

i try anithing, (but not temporarry table), to eliminate cross data, but ... , can you help please, how i get my result?

Rado, thanx very much.

SkinHead May 17th, 2007 9:32 pm
Re: cross data please heslp
 
It's Not Too Clear What You Want.

1. A Query That Gives You Rows Where id1<id2 ?

2. A Query That Gives You Rows Where id2<id1 ?

You Mentioned Temporary Tables, So Either You're Making Things Too Complicated Or I'm Completely Missing The Point !

campkev May 21st, 2007 6:20 pm
Re: cross data please heslp
 
select distinct case when id1<id2 then id1 else id2 end, case when id1<id2 then id2 else id1 end from tablename

cfAllie May 21st, 2007 7:02 pm
Re: cross data please heslp
 
select t1.*
from theTable t1 join theTable t2
on t1.id2 = t2.id1 and t1.id1 < t2.id1

campkev May 22nd, 2007 10:19 am
Re: cross data please heslp
 
Quote:

Originally Posted by cfAllie (Post 370645)
select t1.*
from theTable t1 join theTable t2
on t1.id2 = t2.id1 and t1.id1 < t2.id1


I don't have time to test this, but i don't think that this will work. This won't show any id1's that don't have a matching id2 or any id2's that don't have a matching one

cfAllie May 22nd, 2007 12:14 pm
Re: cross data please heslp
 
It probably wouldn't. It would give them only

Quote:

i want to get result:

1.row [1,2]
3.row [3,4]
5.row [5,6]



All times are GMT -4. The time now is 8:31 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC