title: Designing Accounting Database - General Ledger vs Sub-Ledgers
body: <p>I've been doing research into the implementation of a double-entry accounting system (specifically using Django as a DB backend). What I am having difficulty understanding is the translation of a &quot;Sub-ledger&quot; and &quot;General Ledger&quot; from the accounting world into the database/software world.</p>
  <p>In accounting, we might see something like:</p>
  <pre><code>Sales Sub-Journal:
  ---------------------------------------------------------------
  Date      Description           Amount        Acct      Balance
  ---------------------------------------------------------------
  Jan 1     Cust. A Sale         500.00          AR         500.00
  Jan 15    Cust. B Sale         300.00          AR         800.00
  
  General Journal:
  ---------------------------------------------------------------
  Date      Description           Acct        Debit      Credit
  ---------------------------------------------------------------
  Jan 15    Sales for Jan          AR          800.00
                                  Sales                   800.00
  </code></pre>
  <p>Effectively, the sub-ledger is copied to the General Ledger with a single journal entry.</p>
  <p>What I'm struggling to understand is the purpose of the Sub-ledger <em>and</em> General Ledger from a database perspective. Couldn't the above three entries be recorded in the DB with only two normal journal entries? This would remove the duplication of data (the $800 recorded in the sub-ledger and the $800 also recorded in the general journal entry)?</p>
  <pre><code>General Journal Entries:
  ---------------------------------------------------------------
  Date      Description           Acct        Debit      Credit
  ---------------------------------------------------------------
  Jan 1     Cust. A Sale           AR         500.00
                                   Sales                 500.00
  
  Jan 15    Cust. B Sale           AR         300.00
                                   Sales                 300.00
  </code></pre>
  <p>I understand that in a paper system, a sub-ledger makes a lot of sense as you can see the detail of the sales transactions throughout a period (a day/week/month, whatever the interval is). Then the general ledger shows the &quot;big picture&quot; of your sales, accounts receivable, etc.</p>
  <p>But in a relational database model, it seems the second example where everything is recorded through journal entries, and there are <strong>no</strong> sub-ledgers, would be far more optimal. You still log every transaction and if you need to see the detail of a specific vendor or customer (the sub-ledgers), you can simply provide a filter list of the journal entries.</p>
  <p>Does that make sense? Am I missing something with the above?</p>