title: Fetch data from a single table with some conditions?
body: <p>I am making a skill sharing website for a project.Tables in database are as follows:</p>
  
  <ol>
  <li><p>users(id,name,email,password)</p></li>
  <li><p>skills(id,skillname)</p></li>
  <li><p>haveskills(id,user_id,skill_id)
     <code>{user_id references id in users and skill_id references id in skills}</code></p></li>
  <li><p>wantskills(id,user_id,skill_id)
     <code>{user_id references id in users and skill_id references id in skills}</code></p></li>
  <li><p>friends(id,user_id1,user_id2)
    <code>{say user with id 1 and 3 are friends then I have two rows first:user_id1=1,user_id2=3;second:user_id1=3,user_id2=1}</code></p></li>
  </ol>
  
  <p>When a user is logged in I have these infos:His </p>
  
  <pre><code>id,haveskill_id(hid),wantskill_id(wid).
  </code></pre>
  
  <p>I want sql query for all the users id whose </p>
  
  <pre><code>haveskill_id=wid,wantskill_id=wid and are NOT friends.
  </code></pre>
  
  <p>Edit:My query which fulfills first two conditions but I am having problem with third condition:</p>
  
  <pre><code>SELECT A.id FROM users A JOIN haveskills B 
   ON (A.id=B.user_id And B.skill_id='$wantskill_id') 
   JOIN wantskills C 
   ON (A.id=C.user_id AND C.skill_id='$haveskill_id');
  </code></pre>