Hi people.
I currently have a PHP script, that retrieves certain numbers from multiple tables in a db, and then adds/substracts these numbers to present a final number.
I have the following SQL queries to get the numbers:
$sql_1 = "SELECT amount_given FROM esh_deposits WHERE user_id = ".$user_id;
$sql_2 = "SELECT amount_given FROM esh_compounds WHERE user_id = ".$user_id.;
$sql_3 = "SELECT amount FROM esh_adjustments WHERE user_id = ".$user_id." AND add_substract = 0";
$sql_4 = "SELECT amount_given, amount_taken FROM esh_withdrawals WHERE user_id = ".$user_id;
$sql_5 = "SELECT amount FROM esh_adjustments WHERE user_id = ".$user_id." AND add_substract = 1";
The returned values from $sql_1, $sql_2, $sql_3 are added to $total_balance. After that, the returned values of $sql_4 and $sql_5 are substracted from $total_balance.
I am trying to convert this to 1 mysql query, but I just can't get the required result. Can anyone help me on this?