LAST()函数用于返回指定列的最后一个值。
语法SQL SELECT LAST()函数:
SELECT LAST (column_name) FROM table_name;
你应该注意到,LAST()函数在MS Access只支持。但也有方法可以得到在MySQL中,SQL服务器,Oracle等数据库的最后一个记录。
SELECT column_name FROM table_name
ORDER BY column_name DESC
LIMIT 1;
SELECT TOP 1 column_name FROM table_name
ORDER BY column_name DESC;
SELECT column_name FROM table_name
ORDER BY column_name DESC
WHERE ROWNUM <
=1;
让我们以客户的例子来检查SQL SELECT LAST的命令:
Customers表
顾客姓名 | 年龄 | 地址 | 支出 |
---|---|---|---|
KAMAL SHARMA | 26 | GHAZIABAD | 6000 |
ROBERT PETT | 23 | NEWYORK | 26000 |
SHIKHA SRIVASTAV | 22 | DELHI | 9000 |
SELECT LAST (CUSTOMER_NAME) AS LAST_CUSTOMER FROM CUSTOMERS;
After that query,you will find the result:
SHIKHA SRIVASTAV
推荐阅读
- SQL SELECT COUNT语句
- SQL SELECT FIRST语句
- SQL SELECT TOP语句
- SQL TEMP临时表
- SQL SELECT DISTINCT语句
- SQL SELECT UNIQUE语句
- SQL SELECT查找语句
- SQL ALTER TABLE修改表
- SQL复制表