Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In a table i am having some records. out of those records, two records having simillar data but only difference in that two records is Record date.

Now i want to retrive the latest record of those 2 records and following the other records.

Adcvice a query for this.

Thanks in Advance
Subhash G.
Posted
Updated 20-Jul-11 21:43pm
v3

select top 1 * from tablename order by recorddate desc
 
Share this answer
 
Comments
subhash04573 21-Jul-11 2:00am    
I have to show only latest record not all records.
RaviRanjanKr 21-Jul-11 2:06am    
hey! its will give you only last records. are you not getting SQL query using top 1*. so how its will give you multiple records.
RaviRanjanKr 21-Jul-11 2:07am    
If you are looking for something else so please be mention in your Question :)
m@dhu 21-Jul-11 2:47am    
Did you try that query gives only one record.
RaviRanjanKr 21-Jul-11 2:02am    
Nice Answer, My 5+
You need to sort the results using order by clause. The sort order will be descending as you need the newest at the top. So the query will be like:

SQL
SELECT * FROM TABLE_NAME ORDER BY DATE_COLUMN_NAME DESC


This will give you all the results. Now filter the rows using top clause.

Hope this helps!
 
Share this answer
 
v2
Comments
subhash04573 21-Jul-11 2:00am    
I have to show only latest record not all records.
Thnks
Ankur\m/ 21-Jul-11 2:21am    
Did I not mention that you can filter the no. of rows using TOP clause?
RaviRanjanKr 21-Jul-11 2:03am    
Nice Answer, My 5+
Ankur\m/ 21-Jul-11 2:21am    
Thanks Ravi!
Hi Subhash,

Find my query:
select * from tablename where recorddate =(select max(recorddate) from tablename)


This will return only 1 row.I think this will help you.

Cheers

-Sugato
 
Share this answer
 
Do u have any auto increment field???
If so then try
Select * from TableName where Id=(Select Max(Id) from TableName)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900