title: Convert rows into columns in MySQL
body: <p>I want to Convert rows to columns (week days name), but I only have one entry per row and the rest of columns are empty (for teacher and time slot). </p>
  
  <p>Table structure:</p>
  
  <p><a href="https://i.stack.imgur.com/2fxfv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2fxfv.png" alt="table structure"></a></p>
  
  <p>the output of follow query:</p>
  
  <p><a href="https://i.stack.imgur.com/orEj6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/orEj6.png" alt="query result"></a></p>
  
  <p>and my query is:</p>
  
  <pre><code> SELECT
   /* Employee section */
   CONCAT(emp.first_name, " ",emp.middle_name,"", emp.last_name) as     employeeFullName,
  
  /* Timetable Entry section */
  CONCAT(ct.start_time," - ",ct.end_time) as Slots,
  
  if(wd.name='Monday',CONCAT(sb.name," - ",bt.name),null) Monday,
  if(wd.name='Tuesday',CONCAT(sb.name," - ",bt.name),null) Tuesday,
  if(wd.name='Wednesday',CONCAT(sb.name," - ",bt.name),null) Wednesday,
  if(wd.name='Thurseday',CONCAT(sb.name," - ",bt.name),null) Thurseday,
  if(wd.name='Friday',CONCAT(sb.name," - ",bt.name),null) Friday,
  if(wd.name='Saturday',CONCAT(sb.name," - ",bt.name),null) Saturday,
  if(wd.name='Sunday',CONCAT(sb.name," - ",bt.name),null) Sunday 
  
  FROM `timetable_entries` te 
  
  left Join `weekdays` wd ON te.weekday_id=wd.id
  left Join `employees` emp  ON te.employee_id=emp.id
  left Join `class_timings` ct  ON te.class_timing_id=ct.id
  left Join `batches` bt  ON te.batch_id=bt.id
  left Join `subject` sb  ON te.subject_id=sb.id
  
  WHERE te.employee_id is not null
  Group By  te.class_timing_id,te.employee_id
  </code></pre>