0

I have a litle bit problem to show the employees name with their academic title / degree. here is i attached the table :

xxx

for example, i want to show the employees name like this : "Dr. Christ Smailling, BSc., M.Eng.".

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Is `fat` somehow related to "title"? What if there are multiple titles? – Gordon Linoff Jul 18 '20 at 13:21
  • of course, and bat related to "title" too. the differences between fat and bat is fat we must put before the name, and bat after name. i can add some "graduate date" column to sort the title by the date. – Faeri Hafriza Jul 18 '20 at 13:26

1 Answers1

2

You could use group_concat to concatenate all the relevant titles a person has and then concat_ws to join everything together:

SELECT   CONCAT_WS(GROUP_CONCAT(fat ORDER BY dh.id SEPARATOR ', '), 
                   e.name,
                   GROUP_CONCAT(bat ORDER BY dh.id SEPARATOR ', '))
FROM     employee e
JOIN     degree_history dh ON e.id = dh.employee_id
GROUP BY e.name
Mureinik
  • 297,002
  • 52
  • 306
  • 350