title: Inheritance in sql. How to create a select statement in Table Per Type Inheritance?
body: <p>The accepted answer for this question is super useful:
  <a href="https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database/3579462">How can you represent inheritance in a database?</a></p>
  
  <p>I really like this solution which he calls Table Per Type Inheritance:</p>
  
  <pre><code>CREATE TABLE policies (
     policy_id          int,
     date_issued        datetime,
  
     -- // other common attributes ...
  );
  
  CREATE TABLE policy_motor (
      policy_id         int,
      vehicle_reg_no    varchar(20),
  
     -- // other attributes specific to motor insurance ...
  
     FOREIGN KEY (policy_id) REFERENCES policies (policy_id)
  );
  
  CREATE TABLE policy_property (
      policy_id         int,
      property_address  varchar(20),
  
     -- // other attributes specific to property insurance ...
  
     FOREIGN KEY (policy_id) REFERENCES policies (policy_id)
  );
  </code></pre>
  
  <p>However, I don't understand how to do a select statement. At the end of the answer he says:</p>
  
  <blockquote>
    <p>Searching for all the policies regardless of the subtype now becomes very easy: No UNIONs needed - just a SELECT * FROM policies.</p>
  </blockquote>
  
  <p>That will return all the data from policies, but what about the subtypes? Should the statement be this: <code>SELECT * FROM policies INNER JOIN policy_motor ON policies.policy_id=policy_motor.id INNER JOIN policy_property ON policy_property.id=policies.id WHERE date_issued = yesterday</code></p>
  
  <p>For my particular case, I have 70 subtypes. Will I need to inner join all 70 tables or am I missing some easy way to do this?</p>