Er is geen PIVOT-commando in MySQL, maar er zijn oplossingen - Pivot table basics:rows to kolommen... , MySQL-draaitabellen (transformeer rijen naar kolommen) .
Voor jouw geval zou je zoiets als dit kunnen gebruiken -
SELECT AppNo,
MAX(IF(code = 1, Location, NULL)) Location,
MAX(IF(code = 1, Department, NULL)) Department,
1 Code1,
MAX(IF(code = 2, Location, NULL)) Location,
MAX(IF(code = 2, Department, NULL)) Department,
2 Code2,
MAX(IF(code = 3, Location, NULL)) Location,
MAX(IF(code = 3, Department, NULL)) Department,
3 Code3,
MAX(IF(code = 4, Location, NULL)) Location,
MAX(IF(code = 4, Department, NULL)) Department,
4 Code4,
MAX(IF(code = 5, Location, NULL)) Location,
MAX(IF(code = 5, Department, NULL)) Department,
5 Code5
FROM <table name>
GROUP BY AppNo
PS U kunt deze query uitvoeren vanuit de opgeslagen routine.