0
I have 3 tables in my DB:
CREATE TABLE IF NOT EXISTS `local` (
`codigo` int(11) NOT NULL AUTO_INCREMENT,
`IMEI` varchar(15) NOT NULL,
`latitude` decimal(10,6) NOT NULL,
`longitude` decimal(10,6) NOT NULL,
`datetime` datetime NOT NULL,
PRIMARY KEY (`codigo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2323 ;
CREATE TABLE IF NOT EXISTS `dispositivos` (
`codigo` int(11) NOT NULL AUTO_INCREMENT,
`IMEI` varchar(15) NOT NULL,
`client` int(11) NOT NULL,
PRIMARY KEY (`codigo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `clientes` (
`codigo` int(11) NOT NULL AUTO_INCREMENT,
`numero_cliente` int(11) NOT NULL,
`nome` varchar(50) NOT NULL,
`login` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
PRIMARY KEY (`codigo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Customers have devices that send messages from their location (with the date of the device itself, so I don’t sort the table by date).
All tables are ordered by the field auto_increment
.
I’d like to know how to get the last row of the table local
from each device to a given client.
For example:
Client 1000 has the devices:
- 111222333444555
- 222333444555666
- 333444555666777
I want to take the last line of 111222333444555
, plus the last line of 222333444555666
and the last line of 333444555666777
.
It worked, thanks! You were the room that answered me (counting other places) and the only one that worked. Thank you very much!
– MagisterMundus
I’m glad. Hug!
– electus