<?php
$inventory_in = $db->get_one("SELECT COALESCE(SUM(Qty), 0)
FROM inventory Where id=12 AND inv_type = 'in' LIMIT 1");
$inventory_out = $db->get_one("SELECT COALESCE(SUM(Qty), 0)
FROM inventory Where id=12 AND inv_type = 'out' LIMIT 1");
$inventory = $inventory_in - $inventory_out;
?>
Possible to combine two queries into one?
Thank you.
Assuming you want both values output you can use SUM/CASE
You may want to add
and inv_type in ('in', 'out')to your where clause but its not required.