加别名:select [id] from (select TP_Title as Title,Type=2, tp_id as [id] from TB_Resource_TeachingPlan UNION ALL select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter)T

解决方案 »

  1.   

    select a.[id] from (select TP_Title as Title,Type=2, tp_id as [id] from TB_Resource_TeachingPlan UNION ALL 
    select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter)a
      

  2.   

    访问子查询要加别名:
    select a.[id] from 
    (select TP_Title as Title,Type=2, tp_id as [id] from TB_Resource_TeachingPlan 
    UNION ALL select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter) A
      

  3.   

    加个别名就行了!
    或者,这样写行吗.
    select  
    tp_id as [id] from TB_Resource_TeachingPlan 
    UNION ALL
    select  
    mat_id as [id] from TB_Resource_Matter[id]也可以求出来!
      

  4.   

    不用外面再一个select直接:
    select tp_id as [id] from TB_Resource_TeachingPlan
    UNION ALL select mat_id as [id] from TB_Resource_Matter
    --因为用union all,重复的也是出来,而且顺序不变,而且第二个mat_id 不一定要别名,默认和第一个select的一样