In my laravel project, i am trying to get aggregate of order total from orders table joined with order_products table. But getting the following error when using table alias in selectRaw clause.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'orders.total' in 'field list' (SQL: select SUM(orders.total) as total,order_products.name from `tm_orders` inner join `tm_order_products` on `tm_order_products`.`order_id` = `tm_orders`.`order_id` group by order_products.name)
The query builder code for the corresponding error is given below
$result = DB::table('orders')
->selectRaw('SUM(orders.total) as total,order_products.name')
->join('order_products', 'order_products.order_id', '=', 'orders.order_id')
->groupByRaw('order_products.name')
->get();
