FIRST function in MySQL

MySQL FIRST
The MySQL FIRST function is used to get the first value of a column.

Syntax:

SELECT column, 
FROM table_name  
LIMIT num_rows;

Parameters:
num_rows: It is used to specify the number of rows to be displayed from the first row of the selected column.

Example 1: Students Table:

ID NAME AGE
1 Joy 10
2 Smiley 13
3 Happy 11
4 James 13
5 Bond 10

 

Query:

SELECT name
FROM students
LIMIT 1;

Output:

NAME
Joy
1 row in set <0.00 sec>

Explanation:
The ‘students’ is an already existing table. Here we are retrieving the first record of the ‘name’ column of the ‘students’ table.

Example 2: Students Table:

ID NAME AGE
1 Joy 10
2 Smiley 13
3 Happy 11
4 James 13
5 Bond 10

 

Query:

SELECT name
FROM students
LIMIT 2;

Output:

NAME Joy Smiley

Explanation:

The ‘students’ is an already existing table. Here we are retrieving the first two records of the ‘name’ column of the ‘students’ table.