title: How to Compare Multiple Columns and Rows of a Table
body: <p>I have a big data table that looks something like this</p>
  
  <pre><code>ID    Marker    Value1    Value2
  ================================
  1     A         10        11
  1     B         12        13
  1     C         14        15
  2     A         10        11
  2     B         13        12
  2     C
  3     A         10        11
  3     C         12        13
  </code></pre>
  
  <p>I want to search this data by the following data, which is user input and not stored in a table:</p>
  
  <pre><code>Marker    Value1    Value2
  ==========================
  A         10        11
  B         12        13
  C         14        14
  </code></pre>
  
  <p>The result should be something like this:</p>
  
  <pre><code>ID    Marker    Value1    Value2    Match?
  ==========================================
  1     A         10        11        true
  1     B         12        13        true
  1     C         14        15        false
  2     A         10        11        true
  2     B         13        12        true
  2     C                             false  
  3     A         10        11        true
  3     C         12        13        false
  </code></pre>
  
  <p>And ultimately this (the above table is not necessary, it should demonstrate how these values came to be):</p>
  
  <pre><code>ID    Matches    Percent
  ========================
  1     2          66%
  2     2          66%
  3     1          33%
  </code></pre>
  
  <p>I'm searching for the most promising approach to get this to work in SQL (PostgreSQL to be exact).</p>
  
  <p><strong>My ideas:</strong></p>
  
  <ol>
  <li>Create a temporary table, join it with the above one and group the result</li>
  <li>Use CASE WHEN or a temporary PROCEDURE to only use a single (probably bloated) query</li>
  </ol>
  
  <p>I'm not satisified with either approach, hence the question. How can I compare two tables like these efficiently? </p>