Função LAST() SQL
- Página anterior SQL first()
- Próxima página SQL max()
Função LAST()
A função LAST() retorna o valor do último registro especificado no campo.
Dica:Pode usar a sentença ORDER BY para ordenar os registros.
Sintaxe SQL LAST()
SELECT LAST(column_name) FROM table_name
Exemplo SQL LAST()
Possuímos a seguinte tabela "Orders":
O_Id | OrderDate | OrderPrice | Customer |
---|---|---|---|
1 | 2008/12/29 | 1000 | Bush |
2 | 2008/11/23 | 1600 | Carter |
3 | 2008/10/05 | 700 | Bush |
4 | 2008/09/28 | 300 | Bush |
5 | 2008/08/06 | 2000 | Adams |
6 | 2008/07/21 | 100 | Carter |
Agora, queremos encontrar o último valor da coluna "OrderPrice".
Usamos a seguinte sentença SQL:
SELECT LAST(OrderPrice) AS LastOrderPrice FROM Orders
O conjunto de resultados é semelhante a isso:
LastOrderPrice |
---|
100 |
- Página anterior SQL first()
- Próxima página SQL max()