-2

I want to get the maximum id of row data. In my table first column is id then firstname. this is the sql command I used to get the max(id) of row data and insert firstname in max(id) row. but it is not working


<?PHP  $maxid=mysql_query("insert into test(firstname) values ('$sym') where id =max('id') ;?>
nik
  • 265
  • 1
  • 3
  • 10

2 Answers2

0

You can achieve your requirement in this way.

UPDATE test
   SET  firstname = '$sym'
 ORDER BY `id` DESC LIMIT 1;
Naga
  • 2,190
  • 3
  • 16
  • 21
0
UPDATE yourtable
   SET  firstname = '$sym'
 WHERE id in (SELECT max(id) from yourtable)
jophab
  • 5,356
  • 14
  • 41
  • 60