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 2005 Forums
 Transact-SQL (2005)
 show record having max date

Author  Topic 

anandbohra
Starting Member

4 Posts

Posted - 2007-07-10 : 07:22:42
Dear all
i am having a SQL table which contains fields scrip,price,ddate

now i want to see only those records where date is max of all dates.

pl give me syntax for the same

select * from tblnsecmbhav_1
having max(ddate)

the above one giving me error

Anand Manmohan Bohra

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-10 : 07:25:48
[code]SELECT scrip, price, ddate
FROM tblnsecmbhav_1
WHERE ddate = (SELECT MAX(ddate) FROM tblnsecmbhav_1)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-10 : 08:43:19
or

Select top 1 columns from table
order by datecol desc

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-10 : 09:30:22
quote:
now i want to see only those records where date is max of all dates.

TOP 1 only give one record. The OP said records


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -