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.
| Author |
Topic |
|
sqlbug
Posting Yak Master
201 Posts |
Posted - 2010-01-12 : 18:08:26
|
| Hi,I am trying to get only one (matching row) from this query with the most recent date value.If I do like -SELECT DATE, STATUS_ID FROM FILEHISTORY_INFOWHERE FILE_NAME = 'ABCD.XML'GROUP BY DATE, STATUS_IDHAVING DATE = MAX(DATE)DATE STATUS_ID---- ---------2010-01-11 13:24:08.853 042010-01-11 13:40:19.107 062010-01-11 13:22:22.200 072010-01-06 15:12:48.917 11Then I get several rows with different dates as you can see. If I use TOP 1 - I get the first matching row in the table.How can I do this?Thanks.sqlbug |
|
|
jcampbell
Starting Member
9 Posts |
Posted - 2010-01-12 : 18:25:02
|
| Not sure what you mean one matching row. If you want to get the most recent record for your where clause you can do thisSELECT top 1 DATE, STATUS_ID FROM FILEHISTORY_INFOWHERE FILE_NAME = 'ABCD.XML'ORDER BY DATE DESC |
 |
|
|
sqlbug
Posting Yak Master
201 Posts |
Posted - 2010-01-12 : 18:34:36
|
| Ooooh....Thanks, I'm pretty dumb at times. |
 |
|
|
jcampbell
Starting Member
9 Posts |
Posted - 2010-01-12 : 20:37:20
|
| no problem, glad I could help |
 |
|
|
|
|
|