title: php MySql QUERY for Friends relations Table help
body: <p>EDIT by:lawrence.</p>
  
  <p>I got the right query now</p>
  
  <blockquote>
    <p>select * 
    from users, friends
    where (users.id=friends.user_id1 and friends.user_id2=$profileID) or (users.id=friends.user_id2 and friends.user_id1=$profileID)  </p>
  </blockquote>
  
  <p>Question answered</p>
  
  <p>I need some help joining results from my friends and users table</p>
  
  <p>This is what my friends table look like  </p>
  
  <pre><code>id     user_id1     user_id2   
  1   |  2         |  3  
  1   |  2         |  4  
  1   |  2         |  5  
  1   |  6         |  2  
  </code></pre>
  
  <p><strong>Users table</strong></p>
  
  <pre><code>id    name  
  2  |  sarah  
  3  |  emma  
  4  |  lawrence  
  5  |  cynthia  
  6  |  suzie  
  </code></pre>
  
  <p>I could easily just have two rows for each relation and do a simple query.<br>
  But i prefer having one row per relation,  </p>
  
  <p>So lets assume that  we are watching page member.php?profile=2<br>
  and there is a list of friends, what does the query look like.  </p>
  
  <p>This works fine if i have two rows per relation but i dont want that....</p>
  
  <pre><code>SELECT * FROM friends, users WHERE friends.user_id1 = $profileID AND friends.user_id2 = users.id ORDER BY friends.id DESC LIMIT 16
  </code></pre>
  
  <p>Do you get me? something along like</p>
  
  <pre><code>SELECT * FROM friends,users WHERE friends.user_id1 = $profileID AND ALSO WHERE friends.user_id2 = $profileID AND THEN GET FROM users WHERE users.id = friends.user_id1 AND ALSO WHERE users.id = friends.user_id2  
  </code></pre>
  
  <p>I hope I made myself clear</p>