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 |
parara
Starting Member
3 Posts |
Posted - 2007-07-06 : 06:30:03
|
Hi everybody,I would like to know how can I get the latest record of sNumber D6S8 from the table? This is the query I have tried but not works:SELECT id, MAX(date) FROM table x WHERE sNumber = D6S8;id----sNumber--------date11-----S1F5-----05/09/2006 08:58:3513-----D6S8-----28/06/2006 14:03:2316-----L0S8-----13/02/2007 10:20:2819-----D6S8-----01/02/2007 11:36:09Thanks!!! |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-07-06 : 06:31:42
|
[code]Select TOP 1 Id, [Date] from TableWhere sNumber = 'D6S8'Order by [date] desc[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
parara
Starting Member
3 Posts |
Posted - 2007-07-06 : 06:50:15
|
Thanks Harsh Athalye,But I think this is not what I want. I have the sNumber and I need to get the latest record(date) and its id number. In the example above, the result I expect is returning id-19 and date- 01/02/2007 11:36:09 by knowing of the sNumber D6S8. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-06 : 06:51:51
|
This?Select TOP 1 id, sNumber, date from TableWhere sNumber = 'D6S8'Order by date desc Peter LarssonHelsingborg, Sweden |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-06 : 06:53:08
|
parara, you must try the suggestions before you decide they do not work...Peter LarssonHelsingborg, Sweden |
 |
|
parara
Starting Member
3 Posts |
Posted - 2007-07-06 : 06:58:24
|
Thanks Peso and harsh_athalye!,Sorry, I had a typing error thats why it was not working. You guys are correct! Thanks for the big help!!!!!parara |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-06 : 07:21:14
|
That's why they invented Copy&Paste Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|