title: UNION table in second query based on the result of first query in Oracle sql
body: <p>I am struggling with following problem (in further I provide pseudocode in order to make my example more understandable)</p>
  <p>Assume I have 2 queries which result I want to union with each other</p>
  <p>What query1 output looks like:</p>
  <pre>
  ID   OFFER
  1    prod_1
  2    prod_2
  3    prod_2
  4    prod_1
  </pre>
  <p>What query2 output looks like:</p>
  <pre>
  ID   SEGMENT
  1    LOW
  2    HIGH
  3    MED
  999  MED
  </pre>
  <p>What I need to do is to union results of this 2 queries, but avoid taking row with ID = 999</p>
  <p>If there any way to do it using UNION by extracting from query2 rows bases on values of column ID which are present in column ID of query2?</p>
  <p>I know that following code is incorrect but it conveys the idea of ​​the question greatly:</p>
  <pre><code>--query1
  (
   SELECT ID, OFFER
   FROM TAB1
   WHERE ID &lt;= 4
  ) RES1
  UNION
  --query2
  SELECT ID, SEGMENT
  FROM TAB1
  WHERE ID IN (SELECT ID FROM RES2)
  </code></pre>
  <p>Result should be as following</p>
  <pre>
  ID   OFFER
  1    prod_1
  2    prod_2
  3    prod_2
  4    prod_1
  1    LOW
  2    HIGH
  3    MED
  </pre>
  <p>Appreciate your help</p>