日期:2014-05-18  浏览次数:20424 次

复合表 的联合 出问题
SQL code
--如下联合---没有问题,
select t1.id,t1.data,t2.data from table1 t1 ,table2 t2 where t1.id=t2.id;
--如果当其中一个表是 复合表时就不行了,
--就是说,当其中一个表是子查询时就不行了
--如下:
select * from 
    table1 as t1,
    select *from
    (
        select t2.id ,t2.data, t3.data from table2 as t2,table3  as t3 where t2.id=t3.id 
    )as tab
where t1.id=tab.id;



------解决方案--------------------
你忘记怎么写了。不允许将select子查询写在where上面的。
SQL code

select * from 
    table1 as t1,
    where t1.id in 
    (
        select t2.id  from table2 as t2,table3  as t3 where t2.id=t3.id 
    )

------解决方案--------------------
SQL code
select * from 
    table1 as t1,
    select *from
    (
        select t2.id ,t2.data as data1, t3.data as data2 from table2 as t2,table3  as t3 where t2.id=t3.id 
    )as tab
where t1.id=tab.id;

------解决方案--------------------
探讨
引用:
josy
(百年树人)

你的代码出错了:
如下:

SQL code

消息 156,级别 15,状态 1,第 4 行
关键字 'select' 附近有语法错误。