SQL FIRST() Function

« Previous Chapter Next Chapter »

The FIRST() Function

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

SQL FIRST() Syntax

SELECT FIRST(column_name) FROM table_name


SQL FIRST() Example

We have the following "Purchases" table:

PU_ID OrderDate OrderPrice Customer
1 2015/11/12 1000 Karmen
2 2015/10/23 1600 Tendulkar
3 2015/09/02 700 Karmen
4 2015/09/03 300 Karmen
5 2015/08/30 2000 Jensen
6 2015/10/04 100 Tendulkar

Now we want to find the first value of the "OrderPrice" column.

We use the following SQL statement:

SELECT FIRST(OrderPrice) AS FirstOrderPrice FROM Purchases

Hint: Workaround if FIRST() function is not supported:

SELECT OrderPrice FROM Purchases ORDER BY PU_ID LIMIT 1

The result-set will look like this:

FirstOrderPrice
1000

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!