title: Convert horizontal table to vertical in oracle
body: <p>I have the following table format:</p>
  
  <pre><code> ID | Key | Value
   --   ---   -----
   1     A     aa    
   2     B     bb
   3     A     ay
   4     C     cc
   5     B     bx
   6     C     ct 
  </code></pre>
  
  <p>I need to convert this table to following format:</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code> A    B    C
  ---  ---  ---
  aa   bb   cc
  ay   bx   ct
  </code></pre>
  
  <p>I looked for PIVOT function in oracle 11g, but the "Key" values in input table is not a fixed set of values, they can be anything. 
  I also looked for other such questions but I am not sure in my case, how the query should be written.</p>
  
  <p>Any help will be appreciated, thanks! </p>
  
  <p><strong>Edited:</strong></p>
  
  <p>For the solution, I want to execute the following query but it gives me error at subquery of IN clause. I don't understand why is that.</p>
  
  <pre><code>Select * from (Select Key, Value, Id from tableName
  pivot (max(Value) for Key IN (SELECT distinct Key from tableName)));
  </code></pre>
  
  <p>Thanks!</p>