I have two tables: osn
+----+---------------------------------+--------+
| id | decimal_num | eri | devices|
+----+---------------------------------+--------+
| 1 | AD2S80AUD | AD2S80AUD | 419 |
| 2 | AD2S99 | AD2S99 | 419 |
| 3 | F2K_14pin | 14pin | F2K |
+----+---------------------------------+--------+
and osn_check
:
+----+--------+------------+------------+-------+------------+------+---------+
| id | osn_id | check_date | check_type | works | conclusion | fio | comment |
+----+--------+------------+------------+-------+------------+------+---------+
| 2 | 1 | 2022-04-29 | 1 | | NULL | NULL | NULL |
| 4 | 1 | 2023-05-24 | 0 | NULL | NULL | NULL | NULL |
+----+--------+------------+------------+-------+------------+------+---------+
I need to select the fields from osn
and osn_check
where osn_check.check_date
is maximal for each group. I execute this query:
select decimal_num, eri, check_date,
concat(date_format(check_date, '%d.%m.%Y'), ' - ',
date_format(date_add(check_date, interval 1 year), '%d.%m.%Y'))
from osn join osn_check on osn_check.osn_id=osn.id
group by osn.id
having check_date=max(check_date);
The result is empty. My desired result would be like this:
AD2S80AUD | AD2S80AUD | 2023-05-24 | 24.05.2023 - 24.05.2024
How can I do this?