Home  >  Article  >  Backend Development  >  数据库更新某整数字段最小的一条数据, 如何写

数据库更新某整数字段最小的一条数据, 如何写

WBOY
WBOYOriginal
2016-06-13 11:10:401044browse

数据库更新某整数字段最小的一条数据, 怎么写?
update tabname set field1='value1' where count in (select min(count) from tabname) limit 1;

这一句会提示:You can't specify target table 'tabname' for update in FROM clause....


------解决方案--------------------
 update tabname set name='value1' where count in (select * from (select min(count) from tabname ) as t) limit 1;

or

update tabname set field1='value1' ORDER BY count ASC LIMIT 1
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn