title: Fetch the data based on min(sort_order)
body: <p>I have a table <strong>Product</strong> which have many Images.</p>
  <p>Product</p>
  <pre><code>id name
  1  Sofa
  2  Bed
  
  </code></pre>
  <p>Images</p>
  <pre><code>id product_id  image_url sort_order
  1  1           &quot;url5&quot;    521
  2  1           &quot;url1&quot;    200
  3  1           &quot;url1&quot;    100
  4  2           &quot;url1&quot;    1
  5  2           &quot;url2&quot;    2
  </code></pre>
  <p>I want to fetch images where sort_order have  minimum value for 100 products like below:</p>
  <pre><code>id  product_id  image_url  sort_order
  3   1           &quot;url1&quot;     100
  4   2           &quot;url1&quot;     1  
  </code></pre>
  <p>I know I need to  use <strong>min(sort_order)</strong>  for images but don't find the correct syntax.
  I am trying the below. but no luck</p>
  <pre><code>select i.*
  from images i
  join product p on p.id = i.product_id
  where p.id in (1, 2, ....)
    and i.sort_order = min(sort_order)
  </code></pre>
  <p>Any help to build the correct query?</p>