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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 need help in query of max(date)

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--------date
11-----S1F5-----05/09/2006 08:58:35
13-----D6S8-----28/06/2006 14:03:23
16-----L0S8-----13/02/2007 10:20:28
19-----D6S8-----01/02/2007 11:36:09

Thanks!!!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-07-06 : 06:31:42
[code]Select TOP 1 Id, [Date] from Table
Where sNumber = 'D6S8'
Order by [date] desc[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-06 : 06:51:51
This?

Select TOP 1 id, sNumber, date from Table
Where sNumber = 'D6S8'
Order by date desc





Peter Larsson
Helsingborg, Sweden
Go to Top of Page

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 Larsson
Helsingborg, Sweden
Go to Top of Page

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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-06 : 07:21:14
That's why they invented Copy&Paste


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -