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

前端 未结 15 1024
借酒劲吻你
借酒劲吻你 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条回答
  •  执念已碎
    2020-12-30 19:19

    If you want to just select the id use select max(id) from customer.

    If you want to select the entire row then use a query like this:

    select c1.*
    from customer c1, (select max(id) as max_id from customer )c2 
    where c1.id=c2.max_id
    

    c2 is an alias for the new temporary table which contains max id. Then its cross product is taken with customer table to get the entire row.

    Here we are writing a query in the from clause, which can often be quite useful.

提交回复
热议问题