title: How to loop in array inside sql query in ruby
body: <p>A user has <code>languages</code>, which is an array of language names. I have this method:</p>
  
  <pre><code>def get_users_by_filtered_langauges(lang)
    users = []
    User.all.each do |u|
      u.languages.each do |l|
        users &lt;&lt; u if lang.include?(l)
      end
    end
  </code></pre>
  
  <p>which takes <code>lang</code>, an array of language names, and returns the users whose <code>languages</code> include some language within <code>lang</code>. For example, if <code>first_user</code> has <code>languages</code> <code>["uk", "us"]</code> and <code>lang</code> is <code>["uk"]</code>, then the method's return value includes <code>first_user</code>.</p>
  
  <p>Is there a way to minimize this and write a SQL query in a simpler way?</p>