I have two tables.Table Products
in which there are two product types ProductType_1
and ProductType_2
, and second table ProductType_2_Items
in which I keep the information that ProductType_1
is contained in ProductType_2
. I need to get the latest (published_at) ProductType_1
for each ProductType_2
.
Products table:
|id | published_at | type |
|---|---------------------|---------------|
| 1 | 2019-04-24 08:23:35 | ProductType_1 |
| 2 | 2019-05-24 08:23:35 | ProductType_1 |
| 3 | 2019-06-24 08:23:35 | ProductType_1 |
| 4 | 2019-04-24 08:23:35 | ProductType_1 |
| 5 | 2019-05-24 08:23:35 | ProductType_1 |
| 6 | 2019-05-24 08:23:35 | ProductType_2 |
| 7 | 2019-05-24 08:23:35 | ProductType_2 |
ProductType_2_Items table:
| ProductType_2_ID | ProductType_1_ID |
|------------------|------------------|
| 6 | 1 |
| 6 | 2 |
| 6 | 3 |
| 7 | 4 |
| 7 | 5 |
Expected result:
|ProductType_1_ID | published_at | ProductType_2_ID |
|-----------------|---------------------|------------------|
| 3 | 2019-06-24 08:23:35 | 6 |
| 5 | 2019-05-24 08:23:35 | 7 |
Thanks for all replies.