title: Get Average value of from one table for a specific row in another table php
body: <p>I am trying to do following.</p>
  
  <p>Select a Hospital with id = hid from table named as hospital. 
  Add a value "overall_rating" to it and get all the ratings and make avg of it from another table named as hrating</p>
  
  <p>here is my query</p>
  
  <pre><code> $statement = $conn-&gt;prepare('SELECT hospital.*,(SELECT AVG(hrating.rating_h) FROM hrating WHERE hid = hospital.hid) as overall_rating WHERE hid=:hid LIMIT 1');
  </code></pre>
  
  <p>Getting this error</p>
  
  <pre><code>{"error":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE hid='44' LIMIT 1' at line 1"}
  </code></pre>
  
  <p>Where am i being wrong.</p>