比如表里字段cid=5的记录有三条
select id from ttt where cid=5这条语句正常情况下会返回3条记录,现在我想让它只返回一行记录,但显示出来的是三个用逗号分隔的ID

解决方案 »

  1.   

    select group_concat(id) from ttt where cid=5;
      

  2.   

    select group_concat(id) from ttt where cid=5 group by cid
      

  3.   

    select group_concat(id) from ttt where cid=5;
      

  4.   

    mysql> select * from ad2008;
    +------+------+
    | id   | cid  |
    +------+------+
    |    1 |    5 |
    |    2 |    5 |
    |   10 |    5 |
    +------+------+
    3 rows in set (0.00 sec)mysql> select group_concat(id) from ad2008 where cid=5;
    +------------------+
    | group_concat(id) |
    +------------------+
    | 1,2,10           |
    +------------------+
    1 row in set (0.00 sec)mysql>
      

  5.   

    我这边怎么返回了这个值啊,[BLOB - 20字节]我看了下字段类型是整型的啊
      

  6.   

    测试用的就是整型啊
    mysql> desc ad2008;
    +-------+---------+------+-----+---------+-------+
    | Field | Type    | Null | Key | Default | Extra |
    +-------+---------+------+-----+---------+-------+
    | id    | int(11) | YES  |     | NULL    |       |
    | cid   | int(11) | YES  |     | NULL    |       |
    +-------+---------+------+-----+---------+-------+
    2 rows in set (0.02 sec)mysql>贴出你的表结构看看。