dbTalk Databases Forums  

Getting one of many possible pairings between 2 rows

comp.databases comp.databases


Discuss Getting one of many possible pairings between 2 rows in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
metaperl
 
Posts: n/a

Default Getting one of many possible pairings between 2 rows - 07-09-2007 , 05:05 PM






Let's say that we can have the following values for columns A, B in a
table:


1, 4
1, 5
2, 8
2, 9
2, 7

How can I select from this table such that I only get one pairing of A
and B and it does not matter which one I get?

So, for the example above, I would get

1, n
2, m

where n is any one of and only one of 4 or 5
and m is any one of and only one of 9 or 7

for a result set consisting of 2 rows. E.g.:

1,4
2,7

FYI, I am using MS-SQL 2000, but I imagine there must a fairly cross-
database way of doing this, so I am asking here.

Thanks in advance,
T


Reply With Quote
  #2  
Old   
David Cressey
 
Posts: n/a

Default Re: Getting one of many possible pairings between 2 rows - 07-09-2007 , 10:00 PM







"metaperl" <metaperl (AT) gmail (DOT) com> wrote

Quote:
Let's say that we can have the following values for columns A, B in a
table:


1, 4
1, 5
2, 8
2, 9
2, 7

How can I select from this table such that I only get one pairing of A
and B and it does not matter which one I get?

So, for the example above, I would get

1, n
2, m

where n is any one of and only one of 4 or 5
and m is any one of and only one of 9 or 7

for a result set consisting of 2 rows. E.g.:

1,4
2,7

FYI, I am using MS-SQL 2000, but I imagine there must a fairly cross-
database way of doing this, so I am asking here.

Thanks in advance,
T

select a, min(b) as b
from tbl
group by a

I arbitrarily chose min as a function to give you one of the values for b.
If it doesn't matter which value you are given, then it should be ok to give
you the min value.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.