Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL]Mysql, Wybór dla każdego id najświeższego wpisu.
newmala
post
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 17.01.2012

Ostrzeżenie: (0%)
-----


Mam tabelkę w mysql
  1. CREATE TABLE `test` (
  2.  
  3. `id` INT NOT NULL ,
  4.  
  5. `last_time_mod` TIMESTAMP NOT NULL ,
  6.  
  7. `dane` VARCHAR(45) NOT NULL )

gdzie kluczem można powiedzieć, że będzie id i last_time_mod.
  1. INSERT INTO test (id,last_time_mod,dane) VALUES (1,current_timestamp(),'x1');
  2. INSERT INTO test (id,last_time_mod,dane) VALUES (1,current_timestamp(),'x2');
  3. INSERT INTO test (id,last_time_mod,dane) VALUES (2,current_timestamp(),'z1');
  4. INSERT INTO test (id,last_time_mod,dane) VALUES (2,current_timestamp(),'z2');
  5. INSERT INTO test (id,last_time_mod,dane) VALUES (3,current_timestamp(),'y1');
  6. INSERT INTO test (id,last_time_mod,dane) VALUES (3,current_timestamp(),'y2');

Czyli mam dane:

  1. '1', '2014-03-17 17:04:05', 'x1'
  2. '1', '2014-03-17 17:04:07', 'x2'
  3. '2', '2014-03-17 17:04:09', 'z1'
  4. '2', '2014-03-17 17:04:11', 'z2'
  5. '3', '2014-03-17 17:04:13', 'y1'
  6. '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
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 18:31