Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a SQL Server table using the latest record

 | number |         date           | 
 +--------+------------------------+
 | p1     |2014-08-23 23:45:49.9902|
 | p1     |2014-08-23 23:46:32.033 |

I have a table in SQL Server as above with thousands of records, I would like to be able to update the latest record

 update tableA  
 set number='p2'
 where date=????

Thanks in advance for the help

I used GETDATE() to save the records

like image 494
Angwenyi Avatar asked Aug 23 '14 22:08

Angwenyi


1 Answers

 update tableA  
 set number='p2'
 where date = (select max(date) from tableA)
like image 135
juergen d Avatar answered Nov 15 '22 06:11

juergen d