title: PL\SQL select first row from column 1 where column 2 is unique
body: <p>I just started learning SQL. I'm using an Oracle DB.</p>
  
  <p>Table emp with column empno, ename, job, mgr, hiredate, sal, comm, deptno.</p>
  
  <p>I want to get the first record from ename column for each deptno and ename have to be sort by asc.</p>
  
  <p>The following SQL works:</p>
  
  <pre><code>Select ename
  from (Select d.ename
  From emp d
  Where d.deptno = 10
  Order by ename asc)
  where rownum &lt;= 1
  Union
  Select ename
  from (Select d.ename
  From emp d
  Where d.deptno = 20
  Order by ename asc)
  where rownum &lt;= 1
  Union
  Select ename
  from (Select d.ename
  From emp d
  Where d.deptno = 30
  Order by ename asc)
  where rownum &lt;= 1
  Union
  Select ename
  from (Select d.ename
  From emp d
  Where d.deptno = 40
  Order by ename asc)
  where rownum &lt;= 1
  </code></pre>
  
  <p>I want to optimise it so I dont need to rewrite it if I add some record to deptno column.</p>
  
  <p>I tried with <code>SELECT</code> distinct like</p>
  
  <pre><code>SELECT ename FROM emp WHERE (SELECT distinct deptno FROM emp)
  </code></pre>