title: What is faster, subselect or distinct (MySQL)?
body: <p>Let me describe my doubt. I have system where I have three entities, Doctor, Patient and Appointment. An appointment has the doctor's id and patient Id.</p>
  
  <p>I need now to retrieve all the patients which have an appointment with a concrete doctor, and I'm not sure what will be faster, a distinct or a subselect for the id's, these are the queries:</p>
  
  <p>using distinct-></p>
  
  <pre><code>SELECT DISTINCT patient.id, patient.name, patient.surname FROM
  appointment INNER JOIN patient ON patient.id = appointment.patientid WHERE
  appointment.doctorid = @id;
  </code></pre>
  
  <p>using subselect-></p>
  
  <pre><code>SELECT patient.id, patient.name, patient.surname FROM patient
  WHERE patient.id IN (select appointment.patientid FROM appointment 
  WHERE appointment.doctorid = @id);
  </code></pre>
  
  <p>Not sure it this will affect, the system will run on a MariaDB cluster.</p>