Problems picking up data in previous record - Mysql

Asked

Viewed 29 times

1

I have this query that returns the last record and the previous 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 intended to take only the record before the last, as I can do?

  • 3

    Try to put the LIMIT 1,1 in place of LIMIT 2

1 answer

2


The LIMIT works as follows:

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

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

In your case, it would be LIMIT 1, 1: Starting from according to element (index 1), bring A record.

More information about this you can find here: https://stackoverflow.com/questions/2224951/return-the-nth-record-from-mysql-query

Browser other questions tagged

You are not signed in. Login or sign up in order to post.