select * from spzs where gsid in (select id from qyml where hybz=1) 
union
select * from spzs where gsid not in (select id from qyml where hybz=1)  
order by gsid desc 
这样吧,又出现错误提示//不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。

解决方案 »

  1.   

    select * from spzs where gsid in (select id from qyml where hybz=1) 
    union all //为什么要加个all 啊
    select * from spzs where gsid not in (select id from qyml where hybz=1)  
    order by gsid desc
      

  2.   

    //不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。
    跟上面的union应该没有关系,肯定是你其它地方用了distinct,
    union all 
    我也不清楚
      

  3.   

    不使用all,如果有重复的数据,将只显示一条
    比如:
    select 1,2
    union all
    select 1,2

    select 1,2
    union
    select 1,2的区别是, 第一个查询显示2条,后一个查询显示1条。
      

  4.   

    select * from spzs where gsid in (select id from qyml where hybz=1) 
    union all 
    select * from spzs where gsid not in (select id from qyml where hybz=1)  
    order by gsid desc我还想问个问题,就是这是显示所有的信息吧,然后满足上面条件的按gsid往前排如果我想选择前10个都在两个条件里面,怎么写啊!
      

  5.   

    select top 10 * from spzs where gsid in (select id from qyml where hybz=1)  OR gsid not in (select id from qyml where hybz=1)  order by gsid desc
      

  6.   

    select * into #t from spzs where gsid in (select id from qyml where hybz=1) 
    order by gsid desc 
    select * from #t
    union all
    select * from spzs where gsid not in (select id from qyml where hybz=1) 
      

  7.   

    where gsid in (select id from qyml where hybz=1)  OR gsid not in (select id from qyml where hybz=1)这个跟没where是一样的前10条,你干脆用
    select top 10 * from qyml
    order by gsid desc