问一个简单的sql语句 我不会
  希望你们可以给我点提示  问题如下:   有2个表 学生表(stu)和教师表(teacher)
   学生表有2个字段,1个是stu_id,另外一个是tea_id,
   教师表有2个字段,1个是tea_id,另一个是tea_name
 
  很简单的表结果
  现在是由于1个学生可以有多个老师,所以我想选出来的记录是这样:
  stu_id  tea_name1,tea_name2,....
  1个学生有多少个老师,有几个老师就选出几个老师,但是都是在一条记录里面的
不知道改怎么做谢谢!

解决方案 »

  1.   

    在一条记录?我不会!下面这样写只能得到多条记录。  希望能有高手写出你的需求语句,我也学习一下
    select stu.stu_id as XUESHENGID, teacher.tea_name as TEACHERNAME from stu, tea where stu.tea_id = teacher.tea_id;
      

  2.   

    select stu.stu_id,group_CONCAT(teacher.tea_name) as teachname from stu  left join teacher on stu.tea_id=teacher.tea_id group by stu_id
    你看看是不是你要的结果。(在mysql 5.0调试)
      

  3.   

    非常感谢楼上的yangxiao_jiang
    给分了