Sunday, March 5, 2017

Laravel Querying Views

I have a view like this:

CREATE VIEW orders_sales AS 
SELECT code, SUM(quantity) * SUM(sale_price) as product_total, shop_id
FROM `orders`
GROUP BY code, product_id

I am trying to query it like this:

$data = DB::table('orders_sales')->get();

I am getting the following error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'pakishops2.orders.shop_id' isn't in GROUP BY (SQL: select * from orders_sales)

I am able to query it in phpmyadmin like select * from orders_sales but it wont query with Laravel.

enter image description here



via Asif Nawaz

Advertisement