How do I get the last row in an SQL table

Discussion in 'Spigot Plugin Development' started by Realm, May 17, 2017.

  1. So I have a table structured like this:
    Code (Text):
    Example table:

    uuid | 1
    uuid | 2
    uuid | 3

    where each 'uuid' is unique.

    My question is, how would I go about getting the value of the last row in that table?
    I.e how would I return the value 3 in this case?
  2. mathhulk

    mathhulk Retired Moderator

    Code (SQL):
    SELECT * FROM `table` ORDER BY column_name DESC LIMIT 1
    That should about do it.
    Code (SQL):
    SELECT * FROM `table`
    Select all values from the table named table.
    Code (SQL):
    ORDER BY column_name DESC
    Order the selection by the descending values of the column named column.
    Code (SQL):
    LIMIT 1
    Limit the selection to only one row.
    • Like Like x 1
  3. Thankyou :)!