Get MAX value in mysql query

前端 未结 3 1609
无人共我
无人共我 2021-01-05 05:38

I have a table

       id     mid    userid    remarks
       1       2       8          7 
       2       2       8          6
       3       2       8               


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 06:05

    for mysql Node.js developers especially

    I was unable to get direct-value in mysql-driver for node.js i.e. when I run the following query

    SELECT MAX(id) FROM Users
    

    and I got the result as [RowDataPacket { MAX(id): 1 }]

    I tried to retrieve the value from object console.log(MAX(id)), but I couldn't

    so I set an alias i.e. maxid

    SELECT MAX(id) as maxid FROM Users
    

    and got it as [RowDataPacket { maxid: 1 }]

    Which I can retrieve as console.log(maxid)

提交回复
热议问题