Hi I have data similar to for table : fruit_table
| Product Code | Product | Date |
|---|---|---|
| MG | Mango | 2020-01-25 |
| MG | Mango | 2020-01-26 |
| MG | Mango | 2020-01-27 |
| MG | Mango | 2020-01-28 |
| BN | Banana | 2019-01-15 |
| BN | Banana | 2020-01-19 |
| BN | Banana | 2020-01-20 |
| BN | Banana | 2016-01-20 |
| AP | APPLE | 2021-03-02 |
As you can see in the data we have Mango 4 products and Banana 4 Products and Apple with 1 product, i want the solution is to limit the products with 2 rows with latest date.
And i want output similar to
| Product Code | Product | Date |
|---|---|---|
| MG | Mango | 2020-01-27 |
| MG | Mango | 2020-01-28 |
| BN | Banana | 2020-01-19 |
| BN | Banana | 2020-01-20 |
| AP | APPLE | 2021-03-02 |
How can this be achieved with a simple query in PostgreSQL query. Thanks in advance.