SELECT li.client_id, group_concat(li.percentage ORDER BY li.views ASC SEPARATOR ',') AS views, group_concat(li.percentage ORDER BY li.percentage ASC SEPARATOR ',') FROM li GROUP BY client_id;