title: Oracle sql query union operation?
body: <p>I have two tables. <code>TableA</code> and <code>TableB</code>. both the tables has some data with two columns as below.</p>
  
  <pre><code>TableA
  ---------
  id  Name
  --- ----
  1   abc
  2   def
  
  TableB
  ---------
  id  Name
  --- ----
  1   xyz
  2   pqr
  </code></pre>
  
  <p>Now i would pass list of ids from my application and get same ids along with their names as:</p>
  
  <pre><code>select id, name 
  from TableA 
  where id in(1,2) 
  union select id, name 
  from TableB 
  where id in(1,2);
  </code></pre>
  
  <p>above query gives results as:</p>
  
  <pre><code>1   abc
  1   xyz
  2   def
  2   pqr
  </code></pre>
  
  <p>But what i need is if same id is present in both the tables then TableB's Name should be considered but not TableA's name.</p>
  
  <pre><code>Expected output:
  
  1   xyz
  2   pqr
  </code></pre>
  
  <p>One more is, if TableB does not contain any data then TableA's data should be fetched.</p>
  
  <p>How can i do that?</p>
  
  <p>Thanks!</p>