title: Order by in Unnest
body: <p>Explain my Problem with Sample Query</p>
  
  <pre><code>select p1.zonename,p1.beatname,p1.groupname,p2.partyname,p2.amount,
  p2.groupofcompany from 
  party1 p1 inner join party2 p2 on p1.txno=p2.txno 
  </code></pre>
  
  <p>This Query show result like this</p>
  
  <pre><code>ZoneName BeatName GroupName PartyName Amount Groupofcompany
   AA        BB         CC       A        100        Y
   AA        BB         CC       B        200        Y
   DD        EE         FF       C        300        N
  </code></pre>
  
  <p>But i want display like this</p>
  
  <pre><code>  AA          --&gt; Zone Name
    BB          --&gt; Beat Name
    CC          --&gt; Group Name (if groupofcompany y then only show other wise not)
    A      100  --&gt; Party Name And Amount
    B      200
    DD
    EE     
    C      300  
  </code></pre>
  
  <p>So, I tried Like this</p>
  
  <pre><code>SELECT unnest(array[zonename,beatname,groupname,partyname]) AS partyname,
         unnest(array[0,0,0,amount]) AS Amount,
         unnest(array[1,2,3,4]) AS
  ORDER,
         row_number() over()
  FROM
    (SELECT p1.zonename,
            p1.beatname,
            CASE
                WHEN p2.groupofcompany='N' THEN ''
                ELSE p1.groupname
            END AS groupname,
            p2.partyname,
            p2.amount,
     FROM party1 p1
     INNER JOIN party2 p2 ON p1.txno=p2.txno) AS tt
  ORDER BY row_number() over(),ORDER
  </code></pre>
  
  <p>Its Show Output like this</p>
  
  <pre><code> Party Name Amount Order Row_number
  
        AA             1      1
        BB             2      1
        CC             3      1
        A      100     4      1
        AA             1      2
        BB             2      2
        CC             3      2
        B      200     4      2
        DD             1      3
        EE             2      3
                       3      3
        C      300     4      3
  </code></pre>
  
  <p>But i want to get like this</p>
  
  <pre><code>Party Name Amount
  
        AA            
        BB            
        CC            
        A      100    
        B      200     
        DD             
        EE            
        C      300    
  </code></pre>
  
  <p>How to remove duplicate and correct order (zonename,beatname,groupname,partyname)</p>
  
  <p>Am using <strong>Postgresql 9.3</strong></p>