Table structure: create table test_tmp (
id int,
log_time datetime,
item varchar (10)
)
create table test_d (
id int,
name varchar (10)
)
Test data:
insert into test_d values (1, "hh");
insert into test_d values (2," xx");
insert into test_tmp values (1, "2018-08-16 16 hh" 13 hh" 36 cycles," a");
insert into test_tmp values (1, "2018-08-16 16 13 hh" 36 cycles," b");
insert into test_tmp values (1, "2017-08-16 16 13 hh" 36 cycles," a");
insert into test_tmp values (1, "2017-08-16 16 br 1336," b");
insert into test_tmp values (1, "2018-08-16 16 13 br 36," a");
insert into test_tmp values (2, "2018-08-16 16 br 1336," a");
insert into test_tmp values (2, "2018-08-16 16 br 1336," b");
insert into test_tmp values (2, "2017-08-16 16 br 1336," a");
insert into test_tmp values (2, "2017-08-16 16 13 br 36," b");
insert into test_tmp values (2, "2017-08-16 16 13 13 36," c");
I can only get all of what I write now. How can I get the item (separated by commas) of the most recent record (time) of each id?
select * from test_d d left join (select id, log_time, group_concat (item) from test_tmp group by id, log_time) t on d.id = t.id