创建视图后,子查询返回多行

时间:2012-08-07 07:20:56

标签: mysql view

CREATE VIEW `report_central_class` AS
SELECT a.*,b.course_title,b.outline_id,c.catid,d.main_title,
      (select comp_name 
       from lang_company_details 
       where comp_id = (select comp_id 
                        from lang_company_details_courses 
                        where course_id=a.course_id)
       ) as company, 
       (select concat(fname,' ',lname) 
        from lang_course_instructors 
        where slno=a.class_inst_id) as instname 
FROM `lang_course_details_session` as a, 
              `lang_course_details` as b,
              `lang_course_outline` as c,  
              `lang_course_category` as d 
where a.`class_status` != '' and 
      a.course_id=b.course_id and 
      c.outline_id=b.outline_id and 
      c.catid=d.slno;

如果我在没有create view语句的情况下运行此查询,那么它将从数据库返回正确的记录。但当我试图从VIEW运行相同的时候,它显示Subquery返回多行。

此问题在子查询中:

( select comp_name 
  from lang_company_details 
  where comp_id = (
    select comp_id 
    from lang_company_details_courses 
    where course_id=a.course_id
  )
) as company 

如果我删除此查询,那么一切正常,但使用此查询,视图无效。

0 个答案:

没有答案