Retornar 10 ultimos registros da tabela

MySQL

25/10/2016

Bom dia;
Preciso selecionar os 10 últimos registros da tabela , estou tentando das seguintes formas e está dando erro de sintaxe. Estou usando o Workbench 6.3.


SELECT 
    ROW_NUMBER() over (order by id_tabela),
    id_tabela,
    titulo,
    data_inicial
FROM tabela






        SELECT   
            titulo
		   ,data_inicial
	       ,ROW_NUMBER() OVER(PARTITION BY 'data_inicial' ORDER BY 'data_inicial') LINHA
	    FROM ttabela

Laura

Laura

Curtidas 0

Respostas

Sysbase Informática

Sysbase Informática

25/10/2016

Oi Laura, eu não uso MySql mas acredito que você possa fazer a tua ordenação descendente e ao invés de selecionar os últimos 10 registros seleciona os 10 primeiros. Acredito que o MySql deva possuir algo parecido com 10 first como Firebird.
Rafael
GOSTEI 0
Jones Granatyr

Jones Granatyr

25/10/2016

Completando a resposta, o SQL poderia ficar assim

SELECT first 10
id_tabela,
titulo,
data_inicial
FROM tabela order by id_tabela desc
GOSTEI 0
Laura

Laura

25/10/2016

Completando a resposta, o SQL poderia ficar assim

SELECT first 10
id_tabela,
titulo,
data_inicial
FROM tabela order by id_tabela desc



Obrigada pela ajuda Rafael, mas eu usei o LIMIT

ORDER BY id_tabela desc LIMIT 10
GOSTEI 0
POSTAR