title: Example of inheritance on a database (logical data model)
body: <p><a href="https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database">Here</a>, there are a great answer about this question but i don't found clear examples about what's next, for example, queries (select).</p>
  
  <p>I'm going to describe an example and I want to know if i do correctly so:</p>
  
  <p>We have a base class about payments:</p>
  
  <pre><code>Payments( code_payment (PK), description )
  </code></pre>
  
  <p>And then, we have 3 sub-class (3 differents types of payments on inheritance ):</p>
  
  <pre><code>Cash( code_payment (FK) )
  CreditCard( creditcard_account , code_payment(FK) )
  PromissoryNote( pay_date , code_payment(FK) )
  </code></pre>
  
  <p><strong>For example:</strong> for insert statements, <strong>first</strong>, insert on Payments table and <strong>second</strong>, depending of <em>type of payments</em> ( I think in code you use if/else clause to separate the types of payments and do the correct "insert statement"), insert where belongs. And what happens with select statements?</p>
  
  <p>Imagine that i want to know what type of payment had a specific document assuming that I have a table called <strong>Document</strong> that it is connected with <strong>Payments table</strong> ( so Document table have a foreign key to Payments <em>(code_payment)</em> ).</p>
  
  <p>First i should do is to get the <strong>"description"</strong> of the payments by making a query on Document and Payments table (basically an inner join) and then, <strong>depending of the result</strong> (cash, credic card or promissory note) make a query on the table that belongs.</p>
  
  <p>Is this what I suppose to do? am I on the correct way? Maybe it can works but it looks like a little bit... you know.. no elegant solution. I am a little confuse about that.</p>
  
  <p>Thanks in advance.</p>