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)
 How to retrieve the latest records

Author  Topic 

azharrahi
Starting Member

44 Posts

Posted - 2006-09-08 : 03:37:15

Hi all people
I have a table NewsManagement. It has Three Columns "NewsID, Headline,Detail,Date".
Now I want to retrieve the latest three records(i.e News), that is obviously with respect to date.
That is If there are records from 2nd sep to 8 sep, and there are two records on 8 sep then it must retrieve THE TWO LATEST Records from 8 Sep and One latest Record from previous dates (i.e from 7th sep if there exist the record on the date ...or 6th or 5th ...)
Can anybody help me how to do it.

Azhar Rahi
Software Engineer
Eye4tech Pvt Ltd,Lahore
Pakistan

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-09-08 : 03:46:12
this sounds suspicially school related, so I will just give you some clues how to do this. Plus it is late for me...

anyway, look at using the TOP keyword with ORDER BY DESC in your SELECT statement. If you need more help, just check books online and look at TOP..




-ec
Go to Top of Page

mrsaif
Starting Member

43 Posts

Posted - 2006-09-08 : 03:48:26
select top 3 NewsID, Headline,Detail,Date from newsManagement order by date desc

Muhammad Saifullah
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-09-08 : 03:57:56
quote:
Originally posted by eyechart

this sounds suspicially school related, so I will just give you some clues how to do this. Plus it is late for me...

anyway, look at using the TOP keyword with ORDER BY DESC in your SELECT statement. If you need more help, just check books online and look at TOP..



or, you could just wait for mrsaif to come along and post the answer..




-ec
Go to Top of Page

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2006-09-08 : 04:24:28
Are you happy with the answer ? azharrahi

If it is that easy, everybody will be doing it
Go to Top of Page

azharrahi
Starting Member

44 Posts

Posted - 2006-09-08 : 07:27:51
yes I have always been happy Obinna. ;) well my problem is solved by the query of eyechart and mr saif .. well both queries are same :D.... actually it was very simple solution and when i read the query i felt shameful how easy the solution was and why i was annoying :D ...well thanks all of you

Azhar Rahi
Software Engineer
Eye4tech Pvt Ltd,Lahore
Pakistan
Go to Top of Page
   

- Advertisement -