I need to update the last coloumn in the database in SQL I could use sub queries ie-
UPDATE usertrack SET heading_to = "123" WHERE unique_id=
(select max(unique_id) from usertrack)
If you're using an auto_increment field, you can use the mysql command LAST_INSERT_ID() to identify the last row that has been created. --
How can you be in two places at once when you're not anywhere at all?
In rereading last_insert_id(), it will only ork if you've inserted a value in the current connection. And since I don't think MySQL supports nested selects, you'd have to get the last ID, then use that to update the database separately. Your application might have to do some work and perform two queries:
e.g. in PHP
$query="select max(id) from <table>";
$res=mysql_query($query);
$max_id=mysql_fetch_row($res);
$query="update <table> set <column>=<something> where id=$max_id";
It's a kludge... and only to give you an idea of what I mean. --
How can you be in two places at once when you're not anywhere at all?
Select @simon:=max(last_insert_id(unique_id))
from usertrack
Update usertrack set heading_to="si"
where unique_id=@simon
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
Setting a user defined variable in mysql will keep the variable for the duration of the session, possibly a pain if you have a permanent connection from PHP tho. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.