Pivot query creation in MySQL relies upon the GROUP_CONCAT()
function. If the result of the expression that creates the columns of the pivot query is expected to be large, the value of the group_concat_max_len
variable must be increased:
set session group_concat_max_len = 1024 * 1024; -- This should be enough for most cases