4
I intend to return the last contributor who checked the car products before what you are currently checking.
The car has to be the same and just in case there’s any product checked in the car like Não OK
.
Query:
SELECT nome, DATE(C.DataRegisto4) AS Data, CarrosAla.Descricao,
ListagemPrduto.Descricao, C.Sim, C.DataP, C.Stock, C.Obsevacao3,
(SELECT Colaborador FROM RegistoListagemCarros AS A LEFT OUTER JOIN usuarios AS B
ON B.id = A.Colaborador WHERE A.IdCarro = C.IdCarro ORDER BY A.Id DESC LIMIT 1,1) AS `Colaborador Anterior`
WHERE (C.Sim = 'Não Ok' OR C.DataP = 'Não Ok') AND Colaborador = '33'
AND DATE(C.DataRegisto4) = '2019-08-12'
The problem is in this part of the query:
(SELECT Colaborador FROM RegistoListagemCarros AS A LEFT OUTER JOIN usuarios AS B
ON B.id = A.Colaborador WHERE A.IdCarro = C.IdCarro ORDER BY A.Id DESC LIMIT 1,1) AS `Colaborador Anterior`
Here I intend to return the last collaborator who checked the car, but at this time returns the collaborator who is checking at the moment.
I leave the example with the tables with which I am creating the query:
In the column Colaborador Anterior
should return the collaborator 27, but is returning the 33, which was the last who checked the car.
Can simulate, in this example, a table with the result you expect?
– Sorack
Another thing: what version of
MySQL
that you are using?– Sorack