21. august 2021 - 01:02
Der er
3 kommentarer og 1 løsning
Vælge nyeste timestamp
Hej, Jeg har følgende tabel: id-id_s-navn-timestamp 1-88-mads-2021-02-01 21:21:19 2-87-peter-2021-02-01 21:21:19 3-88-mads-2022-06-09 23:00:00 4-44-ole-2021-02-01 21:21:19 5-54-lars-2021-02-01 21:21:19 ønsker resultat: 2-87-peter-2021-02-01 21:21:19 3-88-mads-2022-02-01 21:21:19 4-44-ole-2021-02-01 21:21:19 5-54-lars-2021-02-01 21:21:19 dvs. hver post med nyeste timestamp for hvert id_s
Annonceindlæg fra HP
23. august 2021 - 01:38
#1
SELECT id,id_s,navn,timestamp FROM tabel t1 WHERE timestamp = (SELECT MAX(timestamp) FROM tabel t2 WHERE t2.id_s = t1.id_s)
23. august 2021 - 18:34
#2
Jeg var lidt for hurtig, har lavet en fejl og glemt oplysning. Dvs finde nyeste timestamp for alle id_s i tabel_2 og joine med id_s i tabel 1. tabel_1: id-id_s-tlf 1-44-66778800 2-54-33445566 3-87-90909090 4-88-80808080 tabel_2: id-id_s-navn-timestamp 1-88-mads-2021-02-01 21:21:19 2-87-peter-2021-02-01 21:21:19 3-88-mads-2022-06-09 23:00:00 4-44-ole-2021-02-01 21:21:19 5-54-lars-2021-02-01 21:21:19 ønsker resultat: 2-87-peter-2021-02-01 21:21:19 - 90909090 3-88-mads-2022-06-09 23:00:00 - 80808080 4-44-ole-2021-02-01 21:21:19 - 66778800 5-54-lars-2021-02-01 21:21:19 - 33445566
24. august 2021 - 01:16
#3
SELECT t1_1.id, t1_1.id_s, t1_1.navn, t1_1timestamp, t2.tlf FROM tabel_1 t1_1 JOIN tabel2 t2 ON t1_1.id_d = t2.id_s WHERE timestamp = (SELECT MAX(timestamp) FROM tabel_1 t1_2 WHERE t1_2.id_s = t1_1.id_s)