Let's say that I have this table:
+-----------+-------+
| name | seat |
+-----------+-------+
| Andrew | 1 |
| Andrew | 5 |
| Andrew | 15 |
| Billy | 2 |
| Billy | 5 |
+-----------+-------+
Is there any way for every name
, to SELECT
the corresponding occurrences of seat
and append them in a single row?
Desired output:
+-----------+-------+-------+-------+
| name | seat1 | seat2 | seat3 |
+-----------+-------+-------+-------+
| Andrew | 1 | 5 | 15 |
| Billy | 2 | 5 | NULL |
+-----------+-------+-------+-------+
I tried a simple SELECT
with GROUP
:
SELECT `name`, seat
FROM users
GROUP BY `name`
ORDER BY `name`;
But it of course outputs 1 column seat
for every name.
+-----------+-------+
| name | seat |
+-----------+-------+
| Andrew | 1 |
| Billy | 2 |
+-----------+-------+
Is that even possible and how?