title: How to translate Postgresql 9.3 query for use on Postgresql 8.4?
body: <p>On development, I have a Postgresql 9.3.10 database, and the following query works perfectly:</p>
  
  <pre><code>@playlist_ids = @playlist.user_ids
  @more_playlists = Playlist.joins(:users).where.not('playlists.id = ? OR playlists.id = ?', 30, 41).where(users: {id: @playlist_ids}).group('playlists.id').order('count(*) desc')
  </code></pre>
  
  <p>In a nutshell, for a Playlist <code>@playlist</code>, this query lists all the other Playlists that share a User with <code>@playlist</code>, ordered by how many they share.</p>
  
  <p>However, on production I'm using a Postgresql 8.4.22 database, so that same query returns this error:</p>
  
  <pre><code>PG::GroupingError: ERROR:  column "playlists.name" must appear in the GROUP BY clause or be used in an aggregate function
  LINE 1: SELECT "playlists".* FROM "playlists" INNER JOIN "playlist...
             ^
  : SELECT "playlists".* FROM "playlists" INNER JOIN "playlist_users" ON "playlist_users"."playlist_id" = "playlists"."id" INNER JOIN "users" ON "users"."id" = "playlist_users"."user_id" WHERE (NOT (playlists.id = 30 OR playlists.id = 41)) AND "users"."id" IN (45, 89, 71, 117, 115, 173, 177, 180, 161, 220, 223, 199, 221, 239, 204, 205, 206, 207, 211, 261, 282, 284, 286, 251, 252, 255, 310, 311, 315, 318, 307, 362, 319, 306, 289, 316, 305, 321, 322, 330, 333, 292, 294, 304, 300, 340, 341, 342, 343, 405, 406, 410, 408, 409, 407, 413, 416, 417, 418, 425, 427, 392, 401, 403, 445, 446, 449, 450, 379, 456, 451, 454, 459, 437, 442, 444, 496, 501, 518, 548, 549, 533, 553, 1112, 1113, 1459, 455, 348, 1458, 242, 1275, 151, 1890, 336, 203, 404, 166, 453, 114, 157, 285, 448, 447, 443, 550, 2167, 2168, 287, 320, 293, 65, 2098, 2097, 2099, 387, 3, 2175, 2170, 2174, 2182, 2171, 438, 2180, 2181, 2169, 2176, 347, 2429, 2177, 2445, 2178, 2447, 58, 2480, 390, 452, 554, 555, 313, 92, 275, 335, 428, 167, 302, 2173, 1538) GROUP BY playlists.id  ORDER BY count(*) desc
  </code></pre>
  
  <p>How can I alter my query to work with Postgresql 8.4?</p>
  
  <hr>
  
  <p><strong>Associations</strong></p>
  
  <pre><code>class Playlist &lt; ActiveRecord::Base
    has_many :playlist_users
    has_many :users, :through =&gt; :playlist_users
  end
  
  class PlaylistUser &lt; ActiveRecord::Base
    belongs_to :playlist
    belongs_to :user
  end
  
  class User &lt; ActiveRecord::Base
    has_many :playlist_users
    has_many :playlists, :through =&gt; :playlist_users
  end
  </code></pre>