title: How select from query inside case in select
body: <p>I have following query</p>
  
  <pre><code>SELECT DISTINCT v.id, 
                  ( CASE 
                      WHEN date IS NULL THEN v.o_id 
                      ELSE (SELECT os 
                            FROM   (SELECT o_id1 os 
                                    FROM   tablet t2 
                                    WHERE  t2.vso_id = v.id 
                                    ORDER  BY date ASC) 
                            WHERE  rownum = 1) 
                    END ) AS p_o, 
                  v.o_id  AS k_o 
  FROM   tablev v 
         LEFT JOIN tablet t 
                ON v.id = t.v_id; 
  </code></pre>
  
  <p>Here is what I need:
  TableV has distinct v.id values. I need join that table with another (tableT) which has many records for same v.id and then for each distinct v.id:</p>
  
  <ol>
  <li>select O_ID from V</li>
  <li>if record for v.id in tableT does not exists(date is null) then
  select O_ID from V (same as above)else select o_id1 from T with
  minimum date</li>
  </ol>
  
  <p>Also, aditional, is if possible to join o_id from 1. and o_id/o_id1 from2 to another table and write person's name?
  I would like, instead of o_id, for each v.id to join selected o_id to another table(tableO) and select name.</p>
  
  <p>So, I need these columns in result: V.id, p_o, k_o
  But it would be really great if it looks like: v.id, p_o.name, k_o.name</p>