Support the ongoing development of Laravel.io →
posted 5 years ago
Last updated 1 year ago.
0

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();
Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.