I'm using MySQL, and trying to sort/join a table with multiple rows of data, so that each year of data is represented in adjacent columns, and if data isn't present, it's represented as null.
+------+------+-----------+
| code | year | enquiries |
+------+------+-----------+
| 1 | 2012 | 302 |
| 2 | 2012 | 274 |
| 3 | 2012 | 288 |
| 4 | 2012 | 301 |
| 5 | 2012 | 192 |
| 1 | 2013 | 406 |
| 3 | 2013 | 297 |
| 4 | 2013 | 199 |
| 1 | 2014 | 254 |
| 2 | 2014 | 396 |
| 3 | 2014 | 187 |
| 4 | 2014 | 213 |
| 5 | 2014 | 316 |
| 6 | 2014 | 222 |
+------+------+-----------+
so that the table above would look like the following:
+------+------+-----------+------+-----------+------+-----------+
| code | year | enquiries | year | enquiries | year | enquiries |
+------+------+-----------+------+-----------+------+-----------+
| 1 | 2012 | 302 | 2013 | 406 | 2014 | 254 |
| 2 | 2012 | 274 | NULL | NULL | NULL | NULL |
| 3 | 2012 | 288 | 2013 | 297 | 2014 | 187 |
| 4 | 2012 | 301 | 2013 | 199 | 2014 | 213 |
| 5 | 2012 | 192 | NULL | NULL | 2014 | 316 |
| 6 | NULL | NULL | NULL | NULL | 2014 | 222 |
+------+------+-----------+------+-----------+------+-----------+
I think that what I should be looking for is a full outer join, but that isn't possible using MySQL.
I managed to get it to join multiple rows together using multiple LEFT OUTER JOINS, but this omits any rows where the data isn't present for all 3 years.