SQL Tutorial

SQL SELECT FIRST and LAST Functions

SQL SELECT FIRST and LAST Functions
SQL SELECT FIRST and LAST Functions

SQL SELECT FIRST and LAST Functions

SQL provides functions to retrieve data efficiently. The FIRST() and LAST() functions fetch the first and last values from a column. Importantly, these are only supported in Microsoft Access ÔÇö MySQL and Oracle use alternatives like LIMIT and ROWNUM.

Complete Python Course with Advance topics:-
SQL Tutorial:-

SQL SELECT FIRST (MS Access)

SELECT FIRST(CUSTOMER_NAME) AS first_customer
FROM CUSTOMER_INFO;
-- Output: ARJUN MEHTA

SQL SELECT LAST (MS Access)

SELECT LAST(STUDENT_NAME) AS last_student
FROM STUDENT_RECORDS;
-- Output: SONIA GUPTA

Alternative in MySQL

-- First record
SELECT STUDENT_NAME FROM STUDENT_RECORDS ORDER BY STUDENT_ID ASC LIMIT 1;

-- Last record
SELECT STUDENT_NAME FROM STUDENT_RECORDS ORDER BY STUDENT_ID DESC LIMIT 1;

Alternative in Oracle

SELECT STUDENT_NAME FROM (
  SELECT STUDENT_NAME FROM STUDENT_RECORDS ORDER BY STUDENT_ID DESC
) WHERE ROWNUM = 1;

Download New Real Time Projects:- Click here
Complete Advance AI topics:-

Conclusion

The FIRST() and LAST() functions are handy but limited to MS Access. For MySQL and Oracle, use ORDER BY with LIMIT or ROWNUM to achieve the same result. Stay updated with more SQL tutorials on .

sql select first and last record of each group
get first and last record from table sql server
select last record in sql without order by
sql select first row
sql select most recent record for each id
select first and last row sql oracle
sql select first last w3schools
sql limit first row

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

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

Chat with us