Contents
SQL LAST: Main Tips
- SQL
SELECT LAST
function brings back the value of the last data record of the defined column. - The type it returns is the same as the Scalar.
Syntax of SQL LAST
SELECT LAST(col_name) FROM tbl_name;
Note: SQL SELECT LAST function is only supported in the MS Access. Therefore, the following workarounds have to be used to retrieve the last record in MySQL, Oracle and SQL server.
Workaround in SQL Server, MySQL and Oracle
SQL Server: Syntax
SELECT TOP 1 col_name FROM tbl_name
ORDER BY col_name DESC;
SELECT TOP 1 Name FROM Customers
ORDER BY ID DESC;

- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid certificates of completion

- Professional service
- Flexible timetables
- A variety of features to choose from
- Professional certificates of completion
- University-level courses
- Multiple Online degree programs

- Great user experience
- Offers quality content
- Very transparent with their pricing
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
MySQL: Syntax
SELECT col_name FROM tbl_name
ORDER BY col_name DESC
LIMIT 1;
Oracle: Syntax
SELECT col_name FROM tbl_name
ORDER BY col_name DESC
WHERE ROWNUM <=1;
SELECT Name FROM Customers
ORDER BY ID DESC
WHERE ROWNUM <=1
Demo Database
In the below table, there is a part of a Customers
table:
ID | Name | Contact | Address | City | Postal_Code | Country |
---|---|---|---|---|---|---|
1 | Ben Choplinks | Ben Choplink | Obeesre Str. 51 | Rome | 11207 | Italy |
2 | Donald Rich | Donald Richario | Avda. de la Confgfstitución 4122 | Tallin | 17021 | Estonia |
3 | Lilly Smilkins | Lilly Smilkin | Matadsderos 2312 | Eguero | 14023 | Mexico |
4 | Brandinina | Tom Hitchins | 110 Hanegover Sq. | London | WB2 2DP | UK |
5 | Carizmos | Christiano Kerrys | Berguvsesvägen 9 | Luleå | S-968 43 | Sweden |
SQL LAST: Example
In the code example below, we make SQL select last value of the column CustomersName
in the table Customer
:
SELECT LAST(Name) AS LastCustomerID FROM Customers;
Latest Udacity Coupon Found:
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!