title: How to optimize my code when left join two table according to the condition in Mysql?
body: <p>I have a field in table t called <code>type</code> which is to show the role ,When type equal student,it return student's name.When type equal teacher,it return teacher's name.Now I have left join two table,Can I left join one table?How to optimize my code?</p>
  
  <pre><code>select t.*,(CASE t.type WHEN 'student' THEN tStudent.sname 
  ELSE tTeacher.tname END) as name 
  from t
  left join t_student tStudent on t.typeid=tStudent .id
  left join t_teacher tTeacher on t.typeid=tTeacher.id
  </code></pre>