title: SQL compare two rows in a table to find how many values are different
body: <p>I have the following table for storing user data:</p>
  
  <p>e.g.</p>
  
  <pre><code>TABLE: users
  COLUMNS:
  ...
  maritalStatus (INT)   - FK
  gender        (CHAR)
  occupation    (INT)   - FK
  ...
  </code></pre>
  
  <p>Now I want to compare two users in this table to see how many columns match for any two given users (say user X &amp;  user Y)</p>
  
  <p>I am doing it via mySQL Stored Procedures by getting each value separately and then comparing them</p>
  
  <p>e.g. </p>
  
  <pre><code>    SELECT maritalStatus from users where userID = X INTO myVar1;
      SELECT maritalStatus from users where userID = Y INTO myVar2;
  
      IF myVar1 = myVar2 THEN
  
      ...
  
      END IF;
  </code></pre>
  
  <p>Is there a shorter way using an SQL query where I can compare two rows in a table and see 
  which columns are different? I dont need to know how much different they actually are, just
  need to know if they contain the same value. Also I will only be comparing selected columns, 
  not every column in the user table.</p>