Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the last record

Status
Not open for further replies.

Gatorajc

MIS
Mar 1, 2002
423
US
What is( if there is one ) the command for getting the last record? For example:

WorkObject Date ActionTaken Completed
5666 2/11/02 Created N
5666 3/2/02 indexed N
5666 3/7/02 routed N
5677 2/11/02 Created N
5677 3/2/02 indexed N
5677 3/7/02 Completed Y
and the list goes on and on. Over 500,000 records.
The last record of each workobject changes so it is not possible to sort or narrow it down by any other field. I need the last record for each WorkObject.

Thanks in advance for any help.
 
Hi,

If you added a Identity column the last record would be the highest value identity column for the Workobject group ie

IdentityCol WorkObject
1 5666
2 5666
3 5666
4 5667

You can use the MAX(IdentityCol) in a select statement to find the last value.

Cheers Dave Dave
dab@completebs.com
See website for more info but we can develop most things for most people.
 
Believe it or not the vendor who created the table did not put a unique field in the table. No primary key nothing at all. But someone else in another forum suggeted MAX() as well I will work with that for a while to see what happens.

Thanks
 
Try using MAX on your date column:

select max(date)
from tablename

-SQLBill
 
SELECT WorkObject, MAX(Date)
FROM TableName
GROUP BY WorkObject
 
You could order the query in reverse order and then just put TOP 1 in the select statement (right at the beginning)

IE

SELECT TOP 1 Primary_key_index, WorkObject ,Date , ActionTaken , Completed
FROM tablename
ORDER BY primary_key_index DESC
 
Judy2000,

Good suggestion, normally. But you missed his second post:

Believe it or not the vendor who created the table did not put a unique field in the table. No primary key nothing at all. But someone else in another forum suggeted MAX() as well I will work with that for a while to see what happens.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top