I have a table where I store companies. Then I have a table movements where I insert several effective amounts / bank and the id of a company from the company table.
Structure of the company table:
idCuCorriente | nBanco |
---+--------------+-----------------
1 | Banco 1 |
2 | Banco 2 |
3 | Banco 3 |
Structure of the Movement table
idCaja | idCuCorriente | mov_efectivo | saldo_efectivo | mov_banco | saldo_banco |
---+--------------+---------------------------------------------------------------------------
1 | 1 | 1,0000 | 1,0000 | 0.00 | 0.00
2 | 2 | 0.00 | 0.00 | 500.00 | 500.00
3 | 2 | 0.00 | 0.00 | 400.00 | 400.00
What I want to list is the most recent record of each company (idCuCorriente) The result would have to leave me like this:
idCaja | idCuCorriente | mov_efectivo | saldo_efectivo | mov_banco | saldo_banco |
---+--------------+---------------------------------------------------------------------------
1 | 1 | 1,0000 | 1,0000 | 0.00 | 0.00
3 | 2 | 0.00 | 0.00 | 400.00 | 400.00
How can I do the SELECT to get this result?