Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
SQL SELECT FIRST and LAST Functions

SQL SELECT FIRST and LAST Functions

Posted on January 24, 2025January 24, 2025 By Rishabh saini No Comments on SQL SELECT FIRST and LAST Functions

SQL SELECT FIRST and LAST Functions

Introduction

Structured Query Language (SQL) provides various functions to retrieve data from a database efficiently. Among these, the FIRST() and LAST() functions are commonly used in Microsoft Access to fetch the first and last values from a specified column. However, these functions are not supported in popular databases like MySQL and Oracle, which offer alternative methods such as LIMIT and ROWNUM.

Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click here

SQL SELECT FIRST

The FIRST() function in SQL is used to return the first value of a selected column. This function is exclusively supported by Microsoft Access.

Syntax:

SELECT FIRST(column_name) FROM table_name;

Example:

Consider the following CUSTOMER_INFO table:

CUSTOMER_NAMEAGEADDRESSEXPENDITURE
ARJUN MEHTA30MUMBAI5000
SARA KHAN25DELHI15000
VIKRAM SINGH28BENGALURU10000

If you want to retrieve the first value of the CUSTOMER_NAME column, the SQL query will be:

SELECT FIRST(CUSTOMER_NAME) AS first_customer FROM CUSTOMER_INFO;

Output:

ARJUN MEHTA

Note: The SELECT FIRST statement is only supported by MS Access and does not work in databases like MySQL and Oracle.

SQL SELECT LAST

The LAST() function is used to retrieve the last value of a selected column. Like FIRST(), it is only available in Microsoft Access. In other databases, alternative approaches such as ORDER BY and LIMIT (for MySQL) or ROWNUM (for Oracle) can be used.

Syntax:

SELECT LAST(column_name) FROM table_name;

Example:

Consider the following STUDENT_RECORDS table:

STUDENT_IDSTUDENT_NAMECOURSEAGEMARKS
201AMIT SHARMABCA2285
202RAHUL VERMAMCA2490
203SONIA GUPTABBA2188

To fetch the last student’s name, the SQL query will be:

SELECT LAST(STUDENT_NAME) AS last_student FROM STUDENT_RECORDS;

Output:

SONIA GUPTA

Alternative Approaches for Other Databases

MySQL:

In MySQL, the LIMIT clause can be used to retrieve the last record:

SELECT STUDENT_NAME FROM STUDENT_RECORDS ORDER BY STUDENT_NAME DESC LIMIT 1;

Output:

SONIA GUPTA

Oracle:

Oracle uses the ROWNUM keyword to achieve similar functionality:

SELECT STUDENT_NAME FROM STUDENT_RECORDS ORDER BY STUDENT_NAME DESC WHERE ROWNUM <= 1;

Output:

SONIA GUPTA

Download New Real Time Projects :-Click here

Conclusion

The FIRST() and LAST() functions are useful for quickly retrieving the first and last values from a column, but they are limited to MS Access. For other databases like MySQL and Oracle, developers must rely on ORDER BY with LIMIT or ROWNUM to achieve similar results.

Stay updated with more SQL tutorials and insights on UpdateGadh.


SQL SELECT FIRST and LAST Functions
sql select first and last record of each group
how to get first and last record from a table in sql server
select last record in sql without order by
select last 10 rows sql
sql select last row with condition
sql select first and last functions record in group
select first and last row sql oracle
sql select most recent record for each id by date
sql select first and last functions w3schools
sql select first and last functions oracle
sql select first and last functions examples

Post Views: 593
SQL Tutorial Tags:advanced functions in sql, analytic function, date functions, dense rank function, functions in sql, rank function, rank function in sql, sql analytic function, sql first and last value functions, sql interview questions and answers, sql pivot function tutorial, sql server interview questions and answers, sql window function, sql window functions, sql windows functions, window function, window function in sql, window functions, windows functions

Post navigation

Previous Post: Contact Management System In PYTHON
Next Post: How to Connect a Database in Python

More Related Articles

SQL INSERT Multiple Rows SQL INSERT Multiple Rows: A Time-Saving Technique SQL Tutorial
SQL FOREIGN KEY SQL FOREIGN KEY: Understanding and Implementing in Relational Databases SQL Tutorial
SQL RENAME TABLE SQL RENAME TABLE: A Complete Guide SQL Tutorial

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. News Portal Project in PHP and MySql Free Source Code
  5. Flipkart Clone using PHP And MYSQL Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme