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 "result" table:
Student_No
|
Subject_No
|
Year_Exam
|
Marks
|
ST101
|
SU03
|
1
|
69
|
ST102
|
SU01
|
1
|
61
|
ST101
|
SU04
|
1
|
70
|
ST101
|
SU05
|
1
|
87
|
ST103
|
SU01
|
2
|
51
|
ST103
|
SU03
|
1
|
59
|
ST103
|
SU01
|
3
|
56
|
ST108
|
SU01
|
1
|
78
|
ST105
|
SU05
|
2
|
98
|
Now we want to find the first value of the "Marks" column.
We use the following SQL statement:
SELECT FIRST(Marks) AS First_Marks FROM result;
Tip: Workaround if FIRST() function is not supported:
SELECT Marks FROM result ORDER BY Student_No LIMIT 1;
The result-set will look like this:
marks
|
69
|
Post a Comment