title: Selecting N amount of MAX and MIN values from the same column
body: <p>I need to select n amount of highest people and n amount of shortest people
  people where the person is MALE. Height is stored in column named 'height' and gender is stored in column named accordingly (as F or M)</p>
  <p><a href="https://i.stack.imgur.com/hiWd9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hiWd9.png" alt="enter image description here" /></a></p>
  <p>I tried something like this</p>
  <pre><code>select name,height from people where gender = 'M' order by height asc limit 5
  </code></pre>
  <p>Then I wanted to just somehow join the result of this and result of the same line but in descending order.</p>
  <p>I also wonder if you could do this in other way.</p>
  <p>I imagined result of this operation would look something like this</p>
  <p><a href="https://i.stack.imgur.com/zUCxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zUCxF.png" alt="enter image description here" /></a></p>
  <p>(height numbers are random but the paired columns on the lefr should contain the highest people and the paired columns on right the shortest)</p>
  <p>I also tried something like this</p>
  <pre><code>(select name,height from people where gender = 'M' order by height desc limit 5) union (select name,height  from people where gender = 'M' order by height asc limit 5) order by height asc
  </code></pre>
  <p>But I don't like ther result since you don't have 2 columns separated as shortest and heighest instead it is all in 1 column and you need to manually count the n amount of people from the top to see which one are highest.</p>
  <p>I am doing this in postgreSQL</p>