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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Most recent date query

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hello all.

I'm trying to get values from a set of data based on the entries being the most recent. A simple example would be.

myTable fields:
Key (int)
Date (DateTime)
DataValue (string)

What would be the syntax for
Select * from myTable where Date (is most recent)

This is not the actual setup, it would just get me the syntax that I am looking for.

Thanks all.
Patrick
Patrick
 
If you are expecting multiple rows, we need to know what you are grouping by (the most recent date for each what). The single row with (or multiple rows sharing) the most recent date can easily be had with:

Code:
SELECT * FROM myTable WHERE Date = (SELECT Max(Date) FROM myTable)

[COLOR=black #e0e0e0]For SQL and technical ideas, visit my blog, Squared Thoughts.

The best part about anything that has cheese is the cheese.[/color]
 
Code:
SELECT YourTable.*
FROM YourTable
INNER JOIN (SELECT MAX(Date) AS Date 
                   FROM YourTable) Tbl1
      ON YourTable.Date = Tbl1.Date


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top