I have two tables: orders and ordersdetail…(partial table)
orders- id(primary key), amount, date( index)
orderdeails- id(primary key), skunitid, quantity, order_id
Each order has multiple order details.
Query:
SELECT Sum(orders.amount), SUM(ordersdetails.quantity)
FROM orders joins orderdetails on ordersdetail.order_id = orders.id
WHERE {{conditions on date column of order table}}
I know its the wrong query, but I want data from both tables in single query (single iteration). When I use a join, the order table's amount comes so many times. How I can get the sum of amount and sum of quantity in single query (I have an index on date column in the order table which has million rows).
I need an efficient way..
Best Answer
Suppose your date range is
2014-12-08
to2014-12-11
This would be the Query you need