PercivalMcGullicuddy
PercivalMcGullicuddy

Reputation: 5533

Picking all records from a table that match smallest date

I have a table that has a few hundred records. Let's say, for simplicity, that it has only two fields (ID and DateModified).

I need to get all records that match the smallest DateModified value in the table.

For example, I have 6 records (ID / DateModified):

ID    DateModified
344   11-June-2011
345    5-June-2011
346    5-June-2011
347   20-June-2011
348    5-June-2011
349   16-June-2011

The query should return records 345, 346 and 348. How would I do this?

Upvotes: 0

Views: 175

Answers (2)

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

select top 1 with ties *
from YourTable
order by DateModified

Upvotes: 1

StevieG
StevieG

Reputation: 8709

SELECT * 
FROM table  
WHERE  DateModifiedvalue = (SELECT min(DateModifiedvalue) 
                            FROM table1 ) 

Upvotes: 4

Related Questions