Mam tabelkę w mysql
CREATE TABLE `test` (
`id` INT NOT NULL ,
`last_time_mod` TIMESTAMP NOT NULL ,
`dane` VARCHAR(45) NOT NULL )
gdzie kluczem można powiedzieć, że będzie id i last_time_mod.
INSERT INTO test (id,last_time_mod,dane) VALUES (1,current_timestamp(),'x1');
INSERT INTO test (id,last_time_mod,dane) VALUES (1,current_timestamp(),'x2');
INSERT INTO test (id,last_time_mod,dane) VALUES (2,current_timestamp(),'z1');
INSERT INTO test (id,last_time_mod,dane) VALUES (2,current_timestamp(),'z2');
INSERT INTO test (id,last_time_mod,dane) VALUES (3,current_timestamp(),'y1');
INSERT INTO test (id,last_time_mod,dane) VALUES (3,current_timestamp(),'y2');
Czyli mam dane:
'1', '2014-03-17 17:04:05', 'x1'
'1', '2014-03-17 17:04:07', 'x2'
'2', '2014-03-17 17:04:09', 'z1'
'2', '2014-03-17 17:04:11', 'z2'
'3', '2014-03-17 17:04:13', 'y1'
'3', '2014-03-17 17:04:15', 'y2'
Jak wybrać te wiersze - pogrupowane po id, dla których last_time_mod jest najświeższy i pokazało prawidłowe dane?
Ten post edytował newmala 17.03.2014, 18:30:36