title: SQL ORDER BY LIKE
body: <p>This is similar to my previous question located <a href="https://stackoverflow.com/questions/17073194/rails-activerecord-sort-by-particular-value">here</a>.Is there any way in SQL (using ActiveRecord) that you can order a relation using the LIKE operator? For instance, I'm querying a relation where one of the columns is a long string that typically contains many comma-separated-values. I would like to order the resulting relation by ordering to the front the records whose value for the aforementioned column matches a smaller string using LIKE (e.g. if my variable is "Spain", then I would like a record with a value like "Ireland, Spain, France" to be ordered to the front of the relation).</p>
  
  <p>I tried this in active record with something like <code>MyModel.order("country_preferences LIKE ?", country)</code>, but got an SQL error. What is the correct way to perform this kind of ordering?</p>
  
  <p><em>Update</em> (extracted from comments):</p>
  
  <p>Using PostgreSQL 9.1. Current SQL error here: <a href="http://pastie.org/8037147" rel="nofollow noreferrer">http://pastie.org/8037147</a> . </p>
  
  <p>5 records where country_preference = "Ireland, Spain, France", 5 records where country_preference = "Ireland, Germany, France". Given a particular country, would like to return a relation where records whose country_preferences string contains this country are ordered to the front.</p>