Solved

How do I select the latest date infor for the multiple dates database

Posted on 2010-11-16
2
303 Views
Last Modified: 2012-05-10
I forgot how to select the data with the latest date from a large database.  Here is an example of my database:

CustomerID   Timestamp                            Expense .....
abc                 11/14/2010 3:30PM              2000.00
abc                 11/15/2010 9:00AM              1500.00
abc                 11/15/2010 9:15AM               1800.00
0
Comment
Question by:jjxia2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34147804
Assuming SQL Server - this can't be Exchange can it?

-- from entire table
select top 1 * from tbl order by timestamp desc

-- latest for each customer
select customerid, timestamp, expense
from
(
select customerid, timestamp, expense,
  rn=row_number() over (partition by customerid order by timestamp desc)
from tbl
) sq
where rn=1
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 34147993
if you are doing this in access


select T.*
from tbl1 as T
Inner Join
(select T2.Customerid, Max(T2.Timestamp) AS MaxOfTimestamp
from tbl1 AS T2
group by T2.Customerid) As T3
On T.Timestamp=T3.MaxOfTimestamp and T.Customerid=T3.Customerid
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question