title: subtract two different sum of column from two different table in select query
body: <p>I have two tables with the name of add_sell and add_expense.
  I have inserted some of value into the tables. I wanted to get the total profit result. I did it myself but the result is showing 0 . Now how can I do that. I also give the total profit formula. Is anyone here to help me? Here is the code given below </p>
  
  <pre><code>function totalSell(){
      global $conn;
      $sql = "SELECT SUM(`sell_amount`) as 'Sumearning' FROM `add_sell` WHERE sell_amount = `sell_amount`";
          $result = $conn-&gt;query($sql);
          $getDate = date('d/m/Y');                    
          if(mysqli_num_rows($result) &gt; 0){
  
          while($fetch = mysqli_fetch_array($result)){                  
          echo "SR ".$fetch['Sumearning']; 
         }
      }
  }
  
  function totalExpense(){
      global $conn;
      $ex = "SELECT SUM(`expense_amount`) as `Sumexpense` FROM `add_expense` WHERE expense_amount = `expense_amount` ";
      $run_ex = $conn-&gt;query($ex);
      if (mysqli_num_rows($run_ex) &gt; 0) {
          while ($tex = mysqli_fetch_array($run_ex)) {
          echo "SR ".$tex['Sumexpense'];
          }
      }
  }
  </code></pre>
  
  <p>function totalProfit(){</p>
  
  <pre><code>    global $conn;
  
      $sql = "SELECT SUM(`sell_amount`) as 'Sumearning' FROM `add_sell` WHERE sell_amount = `sell_amount`";
          $result = $conn-&gt;query($sql);
          $getDate = date('d/m/Y');
          while($fetch = mysqli_fetch_array($result)){                  
              $fetch['Sumearning']; 
              echo "Total Earning : ".$totalEarning = "SR ".$fetch['Sumearning']; 
         }
  
  $ex = "SELECT SUM(`expense_amount`) as `Sumexpense` FROM `add_expense` WHERE expense_amount = `expense_amount` ";
          $run_ex = $conn-&gt;query($ex);
  
          while ($tex = mysqli_fetch_array($run_ex)) {
              $tex['Sumexpense'];
              echo "Total Expense : ".$totlaExpenss = "SR ".$tex['Sumexpense'];
          }
          echo "Your totla Profit is : ".$totalprofit = $totalEarning - $totlaExpenss;
  }
  </code></pre>