title: Determine table to select from based on indicator
body: <p>I have a situation where there are three tables with same table design (same amount of columns, same PK, same FK) but store different value on one date, only one data will be stored per day in each table. Each table has a flag column (Y or N) to determine which should be the value to be reported on the specific day. Only one table's value will be flagged as Y for one CODE in one day.</p>
  
  <p>Example:</p>
  
  <pre><code>Table 1:
  
  Date | Code | Value | Flag 
  01-DEC, ABC,  111, N
  
  Table 2:
  
  Date | Code | Value | Flag 
  01-DEC, ABC,  222, N
  
  Table 3:
  
  Date | Code | Value | Flag 
  01-DEC, ABC,  333, Y
  </code></pre>
  
  <p>Refer to the example above, the value of CODE ABC for date: 01-DEC should be 333 as it's flagged as Y.</p>
  
  <p>How should the SQL look like?</p>