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 2005 Forums
 Transact-SQL (2005)
 first and last in SQL statement

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-06-29 : 09:30:52
In Access VBA, there are "first" or "last" in "Group"
For example,
SELECT Claims.MEMBID, Last(DATEFROM) AS LastOfDATEFROM
FROM Claims GROUP BY MEMBID
How to code in SQL and doing the same job?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-29 : 09:31:43
use min() and max()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-06-29 : 09:31:58
min and max maybe?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-29 : 09:44:59
Last is not necessary same as MAX or MIN.

select *
from (
SELECT *, ROW_NUMBER() OVER (PARTITION BY MembID ORDER BY <sequential column here>) AS theFirst,
ROW_NUMBER() OVER (PARTITION BY MembID ORDER BY <sequential column here> desc) AS theLast
from table1
) AS d
where 1 in (thefirst, thelast)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -