I want to keep the highest report id (Report_ID) for every type (Types) for every single date (Date)
Note: The data column has multiple dates, only 01.01.2021 is shown below.
Question: t1 is the lookup table that I need to use and my challenge is that it does not contain a date column for reference.
select t2.*
from t2
where t1.Report_ID = (select max(t1.Report_ID)
from t1
where t2.Date = ??? and t2.Types = ???
);
t1
Report_ID | Name | Value |
---|---|---|
1 | Name 1 | Value 1 |
2 | Name 2 | Value 2 |
3 | Name 3 | Value 3 |
t2
Date | Types | Report_ID | Name |
---|---|---|---|
01.01.2020 | Type 1 | 1 | Name 1 |
01.01.2020 | Type 1 | 2 | Name 2 |
01.01.2020 | Type 3 | 3 | Name 3 |
view
Date | Types | Name | Value | Report_ID |
---|---|---|---|---|
01.01.2020 | Type 1 | Name 2 | Value 2 | 2 |
01.01.2020 | Type 3 | Name 3 | Value 3 | 3 |