sql last()

SQL Functions

homeBack

Next

SQL LAST()

  • The LAST() Function

    The LAST() function returns the first value of the selected column.

    SQL LAST() Syntax

    SELECT LAST(column_name) FROM table_name

  • SQL LAST() Example

    We have the following “Orders” table:

    OrderID Date Price Customer
    1 2012/12/12 1000 Joy
    2 2012/12/16 1600 Sam
    3 2012/12/22 1700 Arjun
    4 2012/12/23 1300 Joy
    5 2012/12/30 2300 John
    6 2012/12/31 1400 Joy

    Now we want to find the last value of the “Price” column.

    We use the following SQL statement:

    SELECT LAST(Price) AS LastPrice FROM Orders

    Tip: Workaround if LAST() function is not supported:

    SELECT Price FROM Orders ORDER BY OrderID DESC LIMIT 1

    The result-set will look like this:

    LastPrice
    1400

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s