Summary -

In this topic, we described about the Select First with detailed example.

By using SELECT FIRST statement, we can fetch first value of specified column from existing table. SELECT FIRST statement work in MS Access database only.

Syntax -

SELECT FIRST(column_name) FROM table_name; 
  • column_name - Specifies the name of the column.

Syntax for creating user defined name to the required column –

SELECT FIRST(column_name) AS user_defined_name FROM table_name; 
  • user_defined_name- Specifies the name of the output in result-set which is defined by user.

Example

Let us consider below table(s) as an example table(s) to frame the SQL query for getting the desired results.

employee_details -

emp_id emp_name designation manager_id date_of_hire salary dept_id
001 Employee1 Director 2019-07-11 45000.00 1000
002 Employee2 Director 2019-07-11 40000.00 2000
003 Employee3 Manager Employee1 2019-07-11 27000.00 1000
004 Employee4 Manager Employee2 2019-10-08 25000.00 2000
005 Employee5 Analyst Employee3 2019-07-11 20000.00 1000
006 Employee6 Analyst Employee3 2019-10-08 18000.00 1000
007 Employee7 Clerk Employee3 2019-07-11 15000.00 1000
008 Employee8 Salesman Employee4 2019-09-09 14000.00 2000
009 Employee9 Salesman Employee4 2019-10-08 13000.00 2000

Scenario – Get first value of the required column from table.

Requirement – Get first value of the emp_name column in employee_details table. The query was as follows –

SELECT FIRST(emp_name) FROM employee_details; 

By executing above query, we can get output like as shown in below –

emp_name
Employee1

Scenario – Get first value of the required column from table with user defined column name.

Requirement – Getting first row value of salary and name the column as first_salary in employee_details table. The query was as follows –

 SELECT FIRST(salary) FROM employee_details AS first_salary; 

By executing above query, we can get output like as shown in below –

first_salary
45000.00