title: Using UNION select inside a view
body: <p>I have a requirement to check if a specific user is already being referenced to one of our transaction tables (we have around 10 transaction tables). I suggested using a VIEW that will contain all the users that are already referenced, then the DEV team could just SELECT through that table to find out if the data they're looking for is there or not,</p>
  
  <p>so here's my query for the view:</p>
  
  <pre><code>SELECT DISTINCT user_ID
  FROM transaction_table_1
  
  UNION
  
  SELECT DISTINCT user_ID
  FROM transaction_table_2
  
  UNION
  
  SELECT DISTINCT user_ID
  FROM transaction_table_3
  
  UNION
  
  SELECT DISTINCT user_ID
  FROM transaction_table_4
  
  [...]
  </code></pre>
  
  <p>Right now it works, but my question is, is this a good idea? The requirement asks that I only provide a script (or a view) and not a stored procedure, I think this would  be better with an SP since I could just do a quick IF EXIST() statement for each of the table and just check if the parameter user exists in any of the table, but they really wanted it to be only a script they could check (and no using of variables).</p>
  
  <p>Can you guys give me advice on a better way of doing this requirement, that would have less impact on performance since this may not be the optimized solution for this requirement.</p>
  
  <p>TIA,
  Rommel</p>