title: Select value from two tables if the condition for either table matches
body: <p>I have two tables <code>A</code> and <code>B</code> that both have a <code>ObjectID</code> column. <code>A</code> has an unique column <code>ColA</code> among other columns, and <code>B</code> has an unique column <code>ColB</code> among others.</p>
  
  <p>I want to do a SELECT based on a pair of given values for <code>ColA</code> and <code>ColB</code> respectively, such that if a value is found in either column, return the value of <code>ObjectID</code> in the corresponding table. If both values are found (i.e. one is found in <code>ColA</code> and the other is found in <code>ColB</code>), return the matching <code>ObjectID</code>s in both tables (which may or may not be the same). If no value is found for both columns, return empty/null result.</p>
  
  <p>For example, given the tables as below</p>
  
  <pre><code>A
  ...| ObjectID | ColA |...
          1       123
          3       234
          4       345
  
  B
  ...| ObjectID | ColB |...
          2      "abc"
          3      "bcd"
          5      "dce"
  </code></pre>
  
  <p>The query should return <code>(1, 2)</code> if the given value for <code>ColA</code> is <code>1</code> and the given value for <code>ColB</code> is <code>"abc"</code>.</p>
  
  <p>It should return <code>(3, 3)</code> if the given value for <code>ColA</code> is <code>234</code> and the given value for <code>ColB</code> is <code>"bcd"</code>.</p>
  
  <p>It should return <code>(4, null)</code> if the given value for <code>ColA</code> is <code>345</code> and the given value for <code>ColB</code> is <code>"abcd"</code>.</p>
  
  <p>It should return <code>(null, null)</code> if the given value for <code>ColA</code> is <code>1234</code> and the given value for <code>ColB</code> is <code>"abcd"</code>.</p>
  
  <p>Can this be achieved by a <em>single</em> query? Or do I need to create a view of the involved columns from both tables, and SELECT using the view? If so, is there any performance consideration as this query may be executed quite often?</p>