I have two table,

order

```
product_id | name     | quantity
-----------------------------
136        | product1 | 10
137        | product2 | 18
138        | product3 | 5
136        | product1 | 25
136        | product1 | 35

```

product

```
id       | product_id | quantity
-----------------------------
1        | 136        | 100
2        | 137        | 90
3        | 138        | 145
4        | 139        | 100

```

I want the result for remaining quantity, that is add the quantity based upon product\_id in oreder table. This answer subtract from product table based upon product\_id.

For example, i assume product\_id is 136. in oeder table there is three column present. 
To add the quantity (i.e)10+25+35=70.

This value subtracted from quantity of product table. In product table the quantity of product\_id is 100.
so result is 100-70=30.
I want output is 30.
This will follow all other product\_id also.

mysql is,

`$sql = "SELECT op.name, o.quantity-SUM(DISTINCT op.quantity) AS total FROM " . DB_PREFIX . "order op LEFT JOIN`" . DB\_PREFIX . "product`o ON (op.product_id = o.product_id)";`