'Filter multiple id values in MySQL database with Navicat
I need to filter the data with the nearest exp-date and selling-price, without repeating id_product, I try to resolve this problem, but I can't get a proper way to doit
this is Navicat query and result
SELECT
product_exp_date.idproduct,
product_exp_date.exp_date,
product_exp_date.selling_price
FROM
product
INNER JOIN
product_exp_date
ON
product.idproduct = product_exp_date.idproduct
GROUP BY
product_exp_date.exp_date
idproduct exp_date selling_price
8 2022-11-01 300
5 2022-06-08 370
5 2022-06-09 350
7 2022-07-01 380
5 2022-09-20 450
6 2022-10-08 140
6 2023-06-08 150
I already tried this way
GROUP BY
product_exp_date.idproduct
but it's given me different result
idproduct exp_date selling_price
5 2022-06-09 350
6 2023-06-08 150
7 2022-07-01 380
8 2022-11-01 300
but I need to get this result
idproduct exp_date selling_price
5 2022-06-08 370
6 2022-10-08 140
7 2022-07-01 380
8 2022-11-01 300
PRODUCT TABLE
productid product_name
5 A
6 B
7 C
8 D
PRODUCT_EXP_DATE TABLE
idproduct_exp_date idproduct exp_date selling_price
1 5 2022-06-09 350
2 6 2023-06-08 150
3 5 2022-06-08 370
4 5 2022-09-20 450
5 6 2022-10-08 140
6 7 2022-07-01 380
7 8 2022-11-01 300
sometimes's my query has some error, anyway I need help to resolve this problem, Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
