select a from tablename where a in ('MO-01-02-01c')
union all select a from tablename where a not in ('MO-01-02-01c') order by a
  执行后a的'MO-01-02-01c'这个值不见了.. 怎么回事???

解决方案 »

  1.   


    --try:
    select a from tablename where a in ('MO-01-02-01c')
    union all 
    select * from (select a from tablename where a not in ('MO-01-02-01c'))a
    order by a
      

  2.   

    不见了
    什么意思?
    declare @t table(a nvarchar(20))
    insert @t select 'MO-01-02-01c'
    insert @t select 'MO-01-02-01d'
    insert @t select 'MO-01-02-01e'
    insert @t select 'MO-01-02-01f'
    insert @t select 'MO-01-02-01g'
    select a from @t where a in (N'MO-01-02-01c')
    union all 
    select a from @t where a not in (N'MO-01-02-01c') order by a
    /*
    a
    --------------------
    MO-01-02-01c
    MO-01-02-01d
    MO-01-02-01e
    MO-01-02-01f
    MO-01-02-01g(5 個資料列受到影響)*/
      

  3.   


    select a from tablename where a not in ('MO-01-02-01c')
    union all select a from tablename where a in ('MO-01-02-01c') order by a
    就是没有了 .  本来'MO-01-02-01c'这个值 是要查出来的 就是现在查询结果里面 没这个值了
      

  4.   

    select a from tablename where a not in ('MO-01-02-01c')
    union all select a from tablename where a in ('MO-01-02-01c') order by a
    就是没有了 . 本来'MO-01-02-01c'这个值 是要查出来的 就是现在查询结果里面 没这个值了
      是这句话...  要的就是一起执行啊..!
      

  5.   

    单执行这个
    select a from tablename where a in ('MO-01-02-01c') 
    看看是否确定有记录
      

  6.   


    --看是不是数据中存在空格,这样:
    select a from tablename where replace(a,' ','') in ('MO-01-02-01c')
    union all select a from tablename where replace(a,' ','') not in ('MO-01-02-01c') order by a
      

  7.   

    刚才多了个符号..  现在好了 值是有了 但是值的位置还是没变啊...
    我这句话的意思是 先不给他排序  排序后再给它显示出来在原来的位置
    select a from tablename where a in ('MO-01-02-01c')
    union all select a from tablename where a not in ('MO-01-02-01c') order by a
    这句话 order by a之所以放在下面 是因为放在上面 会报union 有语法错误
      

  8.   


    select a from
    (select a,px=0 from tablename where a in ('MO-01-02-01c')
    union all 
    select a,px=1 from tablename where a not in ('MO-01-02-01c'))a
    order by px,a
      

  9.   

    select a from tablename where a in ('MO-01-02-01c') order by a
    union all select a from tablename where a not in ('MO-01-02-01c') 问下 这样行么???  为什么不行?
      

  10.   


    union all时,排序只能在最后,语法问题。