title: Small ms Sql query to get the max of an id with some criteria
body: <p><img src="https://i.stack.imgur.com/S3Tpq.jpg" alt="enter image description here"></p>
  
  <p>I want sql query to get the above result. The result is the maximum Id in TableA whose s_id in TableB has Stat=true i.e. 1.</p>
  
  <p>The following does not do what I want:</p>
  
  <pre><code>select i.category_id,i.image_id,i.image_original,i.image_title,i.photographer 
  from images i 
    inner join schedule s 
      on i.scheduleid=s.scheduleid 
      and s.status='live' 
  where image_id=(select max(image_id) from images)
  </code></pre>