"Darran Kartaschew" <[EMAIL PROTECTED]> wrote:
> Hi Everyone,
>
> Is there an easy way to update a field for the last record referenced by
> an ID number? where that ID number is used on multiple rows?
>
> At the moment I am doing this which works:
>
> CREATE TEMPORARY TABLE tmp_user ( SELECT user_id, MAX(last_updated) AS
> max_last_updated FROM employee GROUP BY user_id);
> UPDATE tmp_user, employee SET picture='My Pic3' WHERE
> employee.user_id='19' AND last_updated=3Dtmp_user.max_last_updated;
>
> Where "user_id" is the user I wish to update, and "picture" is just a
> string (which will hold the filename for their picture).
>
> But this just seems too complicated? So any thoughts?
>
> I'm also using v4.0.18...
If you update data only for one user, you can use ORDER BY and LIMIT in the UPDATE
statement:
UPDATE employee SET picture='My Pic3'
WHERE employee.user_id='19' ORDER BY last_updated DESC LIMIT 1;
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Victoria Reznichenko
/ /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED]
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]