This is giving inaccurate results:
$orders =
DB::table('orders')
->select('orders.id as ordid', 'orders.order_number as order_number',
DB::raw('COUNT(orders_products.product_id) as counter' ) )
->join('orders_products', 'orders.id', '=', 'orders_products.order_id')
->join('products as prod1', 'prod1.id', '=', 'orders_products.product_id')
->join('products as prod2', 'prod1.id', '=', 'prod2.id')
->groupBy( 'orders.order_number')
->orderByRaw('MAX(orders_products.product_id) DESC')
->limit(2)
->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community