title: Get Record based on table result with Three Tables
body: <p>I have four tables, where the data should be checked for 1st table, if doesn't exist, then should check for 2nd table and goes on...</p>
  <p>Currently following approach can be followed</p>
  <pre><code>1. Have union all on the tables and find out the above based on priority (Or)
  2. Run each query from the application and verify and goes one by one (Or)
  3. Using CASE and NOT_EXIST option to find out the rows accordingly
  </code></pre>
  <p>Problems:</p>
  <pre><code>1. Problem with JPA if all columns are extracted with asterisk (*) since count(c.*)
     is not supported in SQL
  2. Performance and unnecessary multiple query from application which needs to be
     avoided in second approach
  3. Makes the query has very complex and not interested to proceed
  </code></pre>
  <p>What would be the best practice to be followed on this use case?</p>
  <p>Thanks</p>