title: Best practice for filtering MySQL results
body: <p>I want to implement a filter-function in my PHP project.
  To implement a filter, I usually just add a WHERE clause in my query to show filtered results.</p>
  
  <p>My Problem is:
  These filters require not only a smple added WHERE clause, but a <strong>huge</strong> Query including multiple JOINs. The resulting Query has > 30 lines.</p>
  
  <p>Later, there should also be a search function which would then also require this huge query.
  I wonder if this is a good practice or if I should add a "redundant" Database column to my database table where I compute the attribute I need for filtering on every update.
  With this column, I wouldnt have my huge query on different places over my project, but have a redundant column.</p>
  
  <p>What do you think?</p>
  
  <p>Greetings</p>
  
  <p><strong>As questioned, here the table structure/code.</strong> This is not the exact code, because there is also a revision system which makes it even more complex, but for understanding this is enough:</p>
  
  <p><strong>table submissions:</strong></p>
  
  <pre><code>ID (primary)
  (additionalColumns)
  </code></pre>
  
  <p><strong>table reports:</strong></p>
  
  <pre><code>ID (primary)
  submissionID (reference to submission table)
  (additionalColumns)
  </code></pre>
  
  <p><strong>table report_objects:</strong></p>
  
  <pre><code>reportID (reference to reports table, multiple report_object for one report)
  </code></pre>
  
  <p><strong>table accounting:</strong></p>
  
  <pre><code>ID (primary)
  reportID (reference to reports table, multiple accountings for one report)
  (additionalColumns)
  </code></pre>
  
  <p><strong>table accounting_objects:</strong></p>
  
  <pre><code>ID
  accountingID (reference to accounting table, multiple accounting_object for one accounting)
  (additionalColumns)
  </code></pre>
  
  <p>For a submission, one or multiple reports are being create with multiple objects to account (report_objects).
  For each report, I can create multiple accountings, where each accounting is for a few objects of the report. The accounted report_objects are stored in accounting_object</p>
  
  <p>My query/filter checks, if each report_object of a submissionID is accounted (accounting_object exists) for one submissionID.</p>