1
I have the tbl_ocorrencias which records occurrences of a particular vehicle. That is, the table consists of the following:
- tbl_ocorrencias -
   id_ocorrencia
   id_viatura
   data
   hora
In this case, an incident has only one vehicle but one vehicle may have several occurrences.
What I want is in the following image:

What’s in the picture is as follows:
- I can only pick up the last 3 occurrences of a particular id_viatura
- Each occurrence found is listed in a column in front as shown in the image
For this I’m trying to do in php and mysql but I’m not getting a solution.