All pastes #432577 Raw Edit

Stuff

public text v1 · immutable
·published 2007-04-10 10:10 UTC
rendered paste body
mysql> select * from test1
    -> ;
+----+----------+
| id | data     |
+----+----------+
|  1 | yes      |
|  2 | no       |
|  3 | maybe    |
|  4 | sure     |
|  5 | probably |
+----+----------+
5 rows in set (0.00 sec)

mysql> select * from test2
+-------+------------+
| fk_id | date       |
+-------+------------+
|     1 | 2007-04-02 |
|     3 | 2007-04-05 |
|     3 | 2006-01-21 |
|     2 | 2006-05-20 |
|     4 | 2007-04-17 |
|     5 | 2007-04-26 |
+-------+------------+
6 rows in set (0.00 sec)

fk_id is the foreign key from the "id" from table "test1" :

mysql> select * from test1 LEFT JOIN test2 ON test1.id = test2.fk_id
    -> ;
+----+----------+-------+------------+
| id | data     | fk_id | date       |
+----+----------+-------+------------+
|  1 | yes      |     1 | 2007-04-02 |
|  2 | no       |     2 | 2006-05-20 |
|  3 | maybe    |     3 | 2007-04-05 |
|  3 | maybe    |     3 | 2006-01-21 |
|  4 | sure     |     4 | 2007-04-17 |
|  5 | probably |     5 | 2007-04-26 |
+----+----------+-------+------------+
6 rows in set (0.00 sec)


Wanted result :

+-----------+------------------+---------------+-----------------------+
| id_concat | data             |     fk_id     | date (concat)         |
+-----------+------------------+---------------+----------+------------+
|  1        | yes              |     1         | 2007-04-02            |
|  2        | no               |     2         | 2006-05-20            |
|  3        | maybe            |     3         | 2007-04-05,2006-01-21 |
|  4,5      | sure, probably   |     4,5       | 2007-04-17,2007-04-26 |
+-----------+------------------+---------------+-----------------------+