Mysql in PHP - how to update only one row in table but with greatest id number

前端 未结 9 2032

I am trying to update fields in my DB, but got stuck with such a simple problem: I want to update just one row in the table with the biggest id number. I would do something like

9条回答
  •  终归单人心
    2021-02-19 03:54

    I have to update a table with consecutive numbers.

    This is how i do.


    UPDATE pos_facturaciondian fdu 
                SET fdu.idfacturacompra = '".$resultado["afectados"]."', 
                fdu.fechacreacion = '".$fechacreacion."'
                WHERE idfacturaciondian = 
                (
                    SELECT min(idfacturaciondian) FROM 
                    (   
                        SELECT * 
                        FROM pos_facturaciondian fds
                        WHERE fds.idfacturacompra = ''
                        ORDER BY fds.idfacturaciondian
                    ) as idfacturaciondian
                )
    

提交回复
热议问题