title: A query to show pairs based on some condition in a join
body: <p>Write a query to display distinct pair of patients who are treated by the same doctor.<br>
  The following tables are present:  </p>
  
  <pre><code>doctor:  
  d_id  
  d_name  
  
  patient:  
  p_id  
  p_name  
  
  treatment:  
  d_id  
  p_id  
  disease  
  medicine  
  </code></pre>
  
  <p>The query:</p>
  
  <pre><code>Select p1.p_name, p2.p_name
  from patient p1, patient p2, treatment t1, treatment t2
  where t1.d_id=t2.d_id 
  AND t1.p_id&lt;&gt;t2.p_id
  AND t1.p_id=p2.p_id
  AND t2.p_id=p1.p_id;
  </code></pre>
  
  <p>Can you suggest a better/alternative query (Oracle style) that eliminates duplicate pairs [like (p1,p6) and (p6,p1)]?</p>