mysql查询在第一行和第二行显示相同的值

时间:2017-04-11 10:38:26

标签: php mysql

我在mysql表中有很多行。我希望将值排序为第一行中值为1的行,第二行中值为2,依此类推。我的表看起来像这样,

id   Columnn1 Column2 name
1     1       1        a
2     2       2        b
3     2       3        c
4     3       2        d
5     3       2        e

我希望结果为

a in first row
b,c in second row
d,e in third row

这是Columnn1

的顺序

3 个答案:

答案 0 :(得分:0)

试试这个:

select group_concat(name) as res from tbl_name order by column1 group by column1;

答案 1 :(得分:0)

使用以下查询

select id,column1,column2,group_concat(name) from table_name
group by column2 order by column2

答案 2 :(得分:0)

use GROUP_CONCAT(name)函数返回一个组中带有concatenated and separated by comma非NULL值的字符串。

select group_concat(name) from tbl_name order by column1 group by column1;