Update the last record with WHERE MYSQL

Asked

Viewed 28 times

1

I wanted to make UPDATE in the last record of the table, where the agent column is equal to "4827"

I tried to use this way but error occurs:

UPDATE login_agent
SET data_hora_login_saida = 'DATA_FIM'
WHERE agente = '4827'
AND  id_log IN (select max(id_log) from login_agent);

Someone could give me a Help ?

1 answer

1

With this query, only the update will be performed if the last record in the table login_agent is owned by Agent 4827.

If you want to update the column data_hora_login_saida from the last agent record 4827, you have to filter max(id_log).

UPDATE login_agent
SET data_hora_login_saida = 'DATA_FIM'
WHERE id_log = (select max(id_log) from login_agent where agente = '4827');
  • Made that mistake ERROR 1093 (HY000): You can't specify target table 'login_agent' for update in FROM clause with your example, do you know what it might be ? @Rovannlinhalis

Browser other questions tagged

You are not signed in. Login or sign up in order to post.