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
 SQL Server Development (2000)
 how to get first row only

Author  Topic 

ceema
Yak Posting Veteran

80 Posts

Posted - 2006-08-29 : 08:33:34
Hello,

I have a table Test with two columns a & b. In table I have values like

A B
-----
1 2
1 3
2 4

I have to retrieve (any one of the distinct values of A and corresponding B value)

a b
-----

1 2
2 4

How it's possible

Ceema

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2006-08-29 : 08:39:01
well if thats the data

wouldn't a simple

SELECT a,min(b)
from ab
group by a

work?

________________________________________________
"Wow, you have a master's degree in psychology? I will order a vodka martini, thanks"
Go to Top of Page

ceema
Yak Posting Veteran

80 Posts

Posted - 2006-08-29 : 08:44:04
Hello,

Data can be even character. So, minimum will not work.

Ceema
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-29 : 08:47:13
can you post more sample data with the expected result ?


KH

Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2006-08-29 : 08:47:47
I guess thats why they ask for the schema.

an easy way is to add a sequential column to the table
and do a self join on the A column, where
ab.key < ab2.key


quote:
Originally posted by ceema

Hello,

Data can be even character. So, minimum will not work.

Ceema




________________________________________________
"Wow, you have a master's degree in psychology? I will order a vodka martini, thanks"
Go to Top of Page

ceema
Yak Posting Veteran

80 Posts

Posted - 2006-08-29 : 08:54:48
Thank you Vivaldi,

Thank you Vivaldi, it's working with min function as you told earlier, now I checked the same for character also.

Thank you once gain and sorry for the wrong reply.


Ceema
Go to Top of Page
   

- Advertisement -