title: Select row with min value of element (if single/multiple rows are present in table)
body: <p>Sample table -</p>
  
  <pre><code>rollno | subj_code | priority
  1      | c45       | 0
  1      | b68       | 1
  1      | a98       | 2
  2      | a98       | 0
  </code></pre>
  
  <p>I want to select a row with min value of <code>priority</code> for that I'm using the below query and its working fine if there are multiple rows in the database (as in the case for <code>rollno = 1</code>).</p>
  
  <pre><code>SELECT subj_code FROM priorities WHERE rollno = roll AND priority = (
      select min(priority) from priorities
  )
  </code></pre>
  
  <p>But in my table it is possible that there is only one entry of a <code>rollno</code> which means only a single row and <code>priority</code> (as in the case for <code>rollno</code> = 2) and in this case the above queries don't give <code>subj_code</code> in return.
  How to get the <code>subj_code</code> in return in this case?</p>
  
  <p>Note - </p>
  
  <ol>
  <li><p>different priority for a particular <code>rollno</code> can't have same values irrespective of the <code>subj_code</code> field.
  ie. the table below is not possible -</p>
  
  <p>rollno | subj_code | priority
  1      | c45       | 0
  1      | b68       | 0</p></li>
  <li><p>Multiple rows can have same <code>priority</code> but the <code>rollno</code> needs to be different in that case.</p></li>
  <li><p>the query gives correct result in this case -</p>
  
  <p>SELECT subj_code FROM priorities WHERE rollno = 1 AND priority = (
          select min(priority) from priorities
      )</p></li>
  </ol>
  
  <p>but doesn't give result in this case -</p>
  
  <pre><code>SELECT subj_code FROM priorities WHERE rollno = 2 AND priority = (
          select min(priority) from priorities
      )
  </code></pre>