title: Query to match multiple column values with multiple rows
body: <p>I have the following table in my postgresql 9.1</p>
  
  <p>Table <code>contact</code>:</p>
  
  <pre><code>contact_id     phone     mobile
  1               123       456
  2               111       222
  3               333       123
  4               222       444
  </code></pre>
  
  <p>Table <code>role</code>:</p>
  
  <pre><code>contact_fk        exchange
  7                 1
  8                 2
  1                 4
  5                 5
  2                 4
  4                 5
  </code></pre>
  
  <p>I need the result like:</p>
  
  <pre><code>contact_id      phone    mobile      exchange
  1               123       456         4
  3               333       123         4
  2               111       222         4
  </code></pre>
  
  <p>I want all the contact data whose mobile field data is in any other contacts phone field and the user must be in exchange 4, which is available in <code>contact_role</code> table </p>
  
  <p>FYI: the contact table contains around 50k rows so joining the contact table to itself taking a lot time, so we must apply the <code>contact_role</code> condition together.</p>