I have two different tables "order" and "item" which i joined using left join. In order table there is a column name called quantity and in item table, there is a column called price. What i need to do is multiply the quantity from order with the price from item then get a total value. There will be several order records added together for the final sum... Can anyone point me, how to code the counting part in php.
You make no reference to your structure and why you are using left join as opposed to an inner join; if you should actually be using inner then you do not need the coalesce in the statement below; it will fetch the price on the orderid you specify in the where clause; SELECT SUM(COALESCE(o.quantity, 1) * COALESCE(i.price,0)) as total FROM orders as o LEFT OUTER JOIN items as i ON (o.itemid=i.itemid) WHERE o.orderid = 1 GROUP BY o.orderid; Code (markup):