Problems fetching data in the previous record - MySQL

1

I have this query that returns the last record and the last one:

SELECT Colaborador 
FROM centrodb.Registolistagem 
LEFT OUTER JOIN centrodb.Registolistagem2 ON centrodb.Registolistagem2.IdLista = centrodb.Registolistagem.Id
WHERE Carro = 'G3 Ala B' 
ORDER BY centrodb.Registolistagem.Id DESC LIMIT 2

But now I wanted to pick up only the previous record, how can I do it?

    
asked by anonymous 10.12.2018 / 17:40

1 answer

2

LIMIT works as follows:

SELECT * FROM [TABELA] ORDER BY [COLUNA] LIMIT [INDICE_INICIAL], [NÚMERO_ELEMENTOS]

Where INDICE_INICIAL is the initial element to be fetched - 1, that is, its index, and NÚMERO_ELEMENTOS is the number of records to be fetched after the initial index.

For your case, it would be LIMIT 1, 1 : Starting from second element (index 1), bring A record.

More information about this you can find here: link

    
10.12.2018 / 17:57