Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi guys
m trying to update sql table which has highest id.......can somebody help me.
Posted
Comments
dan!sh 17-Apr-11 1:08am    
Where exactly are you stuck?
Sandeep Mewara 17-Apr-11 1:23am    
trying to update sql table which has highest id.
Can you elaborate your scenario?
R. Giskard Reventlov 17-Apr-11 11:02am    
Why all the 1 votes and where is the question worthy of a 5?

Assuming you use a numeric ID system, the following should work:
SQL
UPDATE myTable SET myField='NewValue' WHERE iD= (SELECT MAX(iD) FROM myTable)

However, be aware that if this is multi-user system, you do not know what record you are updating.

If you want to use this to update the record you recently created, that may not happen!
 
Share this answer
 
UPDATE table_name 

SET cloumn_name = "Value"

WHERE id = (SELECT id FROM table_name ORDER BY id LIMIT 1,1)
 
Share this answer
 
UPDATE Table_Name SET Column_Name = 'Column_Value' WHERE ID = @@Identity
 
Share this answer
 
Something along the lines of this:

update [table]
set [column1] = @Param
where id = (select max(id) from [table])
 
Share this answer
 
I guess this is what you are expecting, but you could also elaborate your question for more help. This is assuming MAX operation works on ID column, i.e. one possibility is ID is an integer.

UPDATE Table_Name SET Column_Name = 'Column_Value' WHERE ID = (SELECT MAX(ID) FROM Table_Name)
 
Share this answer
 
v2
Comments
punk123 21-Apr-11 4:11am    
it is showing error "near ID"
punk123 21-Apr-11 4:13am    
ya ID is integer.......
punk123 21-Apr-11 4:56am    
thanks buddy..................
Member 12594268 23-Jun-16 6:47am    
This work! SUPERB 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