Dec 13, 2022
0
Level 1
Query builder search with sub query
$item_id = $request->item_id;
DB::table('sales')
->join(DB::raw('(SELECT GROUP_CONCAT(stocks.name) AS item_name,COUNT(stocks.id) AS total_item ,sale_items.sale_id FROM stocks INNER JOIN nso007_sale_details AS sale_items ON sale_items.item_id = stocks.id GROUP BY sale_items.sale_id) sale_items'), 'sale_items.sale_id', 'sales.id');
How can I filter by item id and still get related items concated from group by sales? When I add WHERE stocks.id = $item_id on sub query, it returns only item I filter, not all related items from the same group of sale.
Please or to participate in this conversation.