Hi,
I'm trying to get the minimum value product out of matched from db. For eg: the below shows the two rows from DB with same product_id and different store_id. Here i want to pull the least price one (the one with id:3397).
{
"id": "1139",
"store_id": "24",
"product_id": "517",
"price": "130.00"
},
{
"id": "3397",
"store_id": "28",
"product_id": "517",
"price": "120.00"
}
i have tried the following query
products::whereIn('store_id',$stores)
->selectRaw("
id,
store_id,
product_id,
MIN(price) as s_price
")
->where('product_id','517')
->groupBy('product_id')
->get();
but this shows the first product info(id:1139) with the price of second product info(id:3397) of 120.00.
Any help would be appreciated, Thank you.