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)
 first (column) function

Author  Topic 

anjan
Starting Member

21 Posts

Posted - 2005-09-25 : 11:56:32
I'm converting a project to sql server , which is in access now.
plz helpme reg this.

What is the equivalent function in SQL SERVER to get the first value of a column.
we use FIRST(COLUMN) in Access.
it's urgent

hope reply soon....

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-25 : 13:00:11
to get the first value you have to order the column by something, so:
select top 1 col1 from table1 order by col1

Go with the flow & have fun! Else fight the flow
Go to Top of Page

anjan
Starting Member

21 Posts

Posted - 2005-09-25 : 13:31:11
but i'm not using just first(column) in select statment .i'm using along with other fields in the select statement.some fields are having aggregate functrion (sum).

e.g
select f1,f2,sum(f3),f4
from t1
group by f1,f2

now i want to dislay only first value from f4
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-25 : 14:10:05
select f1,f2,sum(f3),min(f4)
from t1
group by f1,f2

Go with the flow & have fun! Else fight the flow
Go to Top of Page

anjan
Starting Member

21 Posts

Posted - 2005-09-29 : 00:34:26
thanks for replying....
but...here my f4 field is integer...
if i write

select f1,f2,f3,min(f4) from table group by f1,f2,f3

i'll get min of f4 of the group,but i want only the first value whatever it is min or max
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 00:50:43
I think you need to use subquery which select top 1 column

Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -