Combine multiple rows into a single row I have the following query result

+-----------+-------------+----------+----------+----------+
| person_id | question_id | answer_1 | answer_2 | answer_3 |
+-----------+-------------+----------+----------+----------+
|         1 |           1 | a1       |          |          |
|         1 |           2 |          | a2       |          |
|         1 |           3 |          |          | a3       |
|         2 |           1 | a4       |          |          |
|         2 |           2 |          | a5       |          |
|         2 |           3 |          |          | a6       |
+-----------+-------------+----------+----------+----------+


This was achieved using LEFT JOIN

How can i format this to result in the following

+-----------+----------+----------+----------+
| person_id | answer_1 | answer_2 | answer_3 |
+-----------+----------+----------+----------+
|         1 | a1       | a2       | a3       |
|         2 | a4       | a5       | a6       |
+-----------+----------+----------+----------+


The first query is a very big one, its using generated column names, so the answer its joined from different tables. Will be ideally to take the result from the first table and convert it to the second table.
SELECT person_id, MAX(answer_1), MAX(answer_2), MAX(answer_3)
FROM (&lt;your_sub_query&gt;) subquery_alias
GROUP BY person_id


would do the job.