¿Cómo puedo hacer en lenguaje SQL para mostrar los últimos 10 registros de una tabla?

Sólo quiero poder mostrar los últimos 10 registros de una tabla con un select.
Si sabes como hacerlo échame un cable.
Gracias, Un saludo.

1 respuesta

1
Respuesta de
Para mostrar los N primeros registros vale con Usar la sentencia TOP. esta funciona asi :
SELECT TOP [Numero de registros] ...
La documentacion del TOP la tienes aqui :
http://users.starpower.net/rjhalljr/Serve/AccSql/sql.html
Por si no la ves es esta...
Returning Groups Of Rows In Sequence
For web pages, you often want to return rows in groups of some number. For example, you may want to insert the first twenty five rows into the first page, the next twenty five into the second page, and so on. If you can't or don't want to do this in the client applications, the following SQL statements will do the job. This approach assumes that the rows in the table are ordered on one column (fldOrder).
SELECT TOP 25 * FROM tbl;
Now it gets a little tricky. To get the next group of twenty five rows, start by selecting the first fifty.
SELECT TOP 50 * FROM tbl;
Now use the query above as a subquery in a query that pulls the bottom twenty five from the selected fifty.
SELECT TOP 25 *
FROM (
SELECT TOP 50 * FROM tbl
)
ORDER BY fldOrder DESC;
That gets the correct twenty five rows, but in the wrong order. The last step is to put them back in the proper order.
SELECT *
FROM (
SELECT TOP 25 *
FROM (
SELECT TOP 50 * FROM tbl
)
ORDER BY fldOrder DESC
)
ORDER BY fldOrder;
The SQL statement above will run, but when you close the query and then reopen it in SQL View, you'll see that Access has changed the statement. Don't worry about it. Either version works.
Espero que esas fueran las dudas que me planteabas...
Un Saludo
Añade un comentario a esta respuesta
Añade tu respuesta
Haz clic para o
Escribe tu mensaje