SQL - How to find the highest number in a column?

前端 未结 15 1027
借酒劲吻你
借酒劲吻你 2020-12-30 18:25

Let\'s say I have the following data in the Customers table: (nothing more)

ID   FirstName   LastName
-------------------------------
20   John        Macken         


        
15条回答
  •  旧时难觅i
    2020-12-30 19:30

    In PHP:

    $sql = mysql_query("select id from customers order by id desc");
    $rs = mysql_fetch_array($sql);
    if ( !$rs ) { $newid = 1; } else { $newid = $rs[newid]+1; }
    

    thus $newid = 23 if last record in column id was 22.

提交回复
热议问题