I have two table in MySQL :
system
Id_system   Name        Type
------------------------------
1           'System1'   'Type1'
2           'System2'   'Type1'
3           'System3'   'Type1'
4           'System4'   'Type2'
measures
Id_system   Sensor  Value   Insert_date
--------------------------------------------------
1           'S1'    12      '2019-23-04 15:16:05'
1           'S2'    2       '2019-23-04 15:16:05'
1           'S3'    42      '2019-23-04 15:16:05'
2           'S1'    11      '2019-23-04 15:11:05'
2           'S2'    3       '2019-23-04 15:11:05'
2           'S3'    43      '2019-23-04 15:11:05'
4           'S1'    2       '2019-23-04 15:10:05'
4           'S2'    32      '2019-23-04 15:10:05'
4           'S3'    2       '2019-23-04 15:10:05'
3           'S1'    32      '2019-23-04 15:06:05'
3           'S2'    54      '2019-23-04 15:06:05'
3           'S3'    15      '2019-23-04 15:06:05'
1           'S1'    10      '2019-23-04 15:00:05'
1           'S2'    1       '2019-23-04 15:00:05'
1           'S3'    35      '2019-23-04 15:00:05'
I would like have as result, the last measures for each systems, like this :
Id_system   Sensor  Value   Insert_date             Name        
---------------------------------------------------------------
1           'S1'    12      '2019-23-04 15:16:05'   'System1'
1           'S2'    2       '2019-23-04 15:16:05'   'System1'
1           'S3'    42      '2019-23-04 15:16:05'   'System1'
2           'S1'    11      '2019-23-04 15:11:05'   'System2'
2           'S2'    3       '2019-23-04 15:11:05'   'System2'
2           'S3'    43      '2019-23-04 15:11:05'   'System2'
3           'S1'    32      '2019-23-04 15:06:05'   'System3'
3           'S2'    54      '2019-23-04 15:06:05'   'System3'
3           'S3'    15      '2019-23-04 15:06:05'   'System3'
I tried this request in sql :
SELECT DISTINCT m.sensor, s.name, m.value, m.date_insert 
FROM system s 
LEFT JOIN measure m ON s.id_system = m.id_system 
WHERE s.type = 'Type1'
but she returns, each measures for each systems, while I just want the last measure of each type for each system :
Id_system   Sensor  Value   Insert_date             Name        
---------------------------------------------------------------
1           'S1'    12      '2019-23-04 15:16:05'   'System1'
1           'S2'    2       '2019-23-04 15:16:05'   'System1'
1           'S3'    42      '2019-23-04 15:16:05'   'System1'
2           'S1'    11      '2019-23-04 15:11:05'   'System2'
2           'S2'    3       '2019-23-04 15:11:05'   'System2'
2           'S3'    43      '2019-23-04 15:11:05'   'System2'
3           'S1'    32      '2019-23-04 15:06:05'   'System3'
3           'S2'    54      '2019-23-04 15:06:05'   'System3'
3           'S3'    15      '2019-23-04 15:06:05'   'System3'
1           'S1'    10      '2019-23-04 15:00:05'   'System1'
1           'S2'    1       '2019-23-04 15:00:05'   'System1'
1           'S3'    35      '2019-23-04 15:00:05'   'System1'
Do you have an idea of how to do it ?
 
    