title: Nested Sum( ) query is not working in mysql
body: <p>i'm having a problem in calculating total bill of a ptient. I have three tables named as "test", "pharmacy", "check".</p>
  
  <p>Columns in <code>test</code> are:</p>
  
  <pre><code>patient_ID 
  testname
  rate
  </code></pre>
  
  <p>Columns in <code>pharmacy</code> are:</p>
  
  <pre><code>patient_ID
  medicineDescription
  qty
  rate
  </code></pre>
  
  <p>Columns in <code>check</code> are:</p>
  
  <pre><code>patient_ID 
  doctorID
  fees
  date
  </code></pre>
  
  <p>I have a table <code>Bill</code> that will store total amount of a patient.</p>
  
  <pre><code>patient_ID
  amount
  date
  </code></pre>
  
  <p>I have used the following query. But it's giving the following error.</p>
  
  <pre><code>$result = mysqli_query($data,  "SELECT patient_ID, (SUM(pharmacy.qty*pharmacy.rate ) + SUM(test.rate) + SUM(check.fees)) 
       AS total FROM pharmacy, test, check  WHERE patient_ID= '$pID'" );
  </code></pre>