I’m using the below query to return the form ids with their attachment ids. Each form can have no attachments, one attachment or two attachments.
SELECT form.id AS 'Form ID',
attachment.id AS 'Attachment ID'
FROM form,
attachment
WHERE form.id = attachment.form_id;
I'm retrieving the results as follows:
+---------+---------------+
| Form ID | Attachment ID |
+---------+---------------+
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
| 5 | 5 |
| 5 | 6 |
| 6 | 7 |
+---------+---------------+
I'm trying to figure out a way to retrieving the results as follows:
+---------+-------------------+-------------------+
| Form ID | Attachment ID - 1 | Attachment ID - 2 |
+---------+-------------------+-------------------+
| 1 | 1 | 2 |
| 2 | 3 | NULL |
| 3 | 4 | NULL |
| 4 | NULL | NULL |
| 5 | 5 | 6 |
| 6 | 7 | NULL |
+---------+-------------------+-------------------+