title: How to get column names that have different values
body: <p>Is there any way to find out column names that do not have same values among two or more records returned by a query?
  I am using ActiveRecord on Rails. </p>
  
  <p>The following code returns a number of records (greater than 1 in my case):</p>
  
  <pre><code>TableName.where(column_1: value)
  </code></pre>
  
  <p>If the above query returns three records, I want to know if there is a way I can compare the three records and get the column names where values do not match or are different?</p>
  
  <p>For example if the above query returns these records:</p>
  
  <pre><code> column_1 | column_2 | column_3 | column_4
  ----------|----------|----------|----------
     value  |    A     |    B     |    C
     value  |    A     |    B     |    C1
     value  |    A     |    B     |    C2
  </code></pre>
  
  <p>How can I compare the above three records and find out which columns have different values? (column_4 in this case). In my original database, I have more than 25 columns and I would need all column names wherever there is a difference.</p>
  
  <p>Note: The query results are returned in an array form and each column can be accessed using <code>records[i].column_name</code>.</p>
  
  <p>Also I need to get this working on Ruby with ActiveRecord as the wrapper. I think this can be done using a large number of nested <code>if</code>/<code>else</code> but there must be an elegant solution to this.</p>
  
  <p>How can I do this?</p>