日期:2014-05-16 浏览次数:20753 次
mysql> select * from table1; +------+------+----------+ | id | oid | userName | +------+------+----------+ | 01 | oye1 | user1 | | 02 | oye2 | user2 | +------+------+----------+ 2 rows in set (0.06 sec) mysql> select * from table2; +------+------+-------+ | id | oid | gname | +------+------+-------+ | 01 | oye1 | aaa | | 02 | oye1 | bbb | | 03 | oye2 | ddd | | 04 | oye2 | ggg | +------+------+-------+ 4 rows in set (0.00 sec) mysql> select table1.oid,group_concat(gname SEPARATOR ''),userName -> from table1 ,table2 -> where table1.oid=table2.oid -> group by table1.oid; +------+-----------------------------------+----------+ | oid | group_concat(gname SEPARATOR '') | userName | +------+-----------------------------------+----------+ | oye1 | aaabbb | user1 | | oye2 | dddggg | user2 | +------+-----------------------------------+----------+ 2 rows in set (0.01 sec) mysql>